私は効率的に私のPHPアプリケーションでgearmanを使用する方法にいくつか疑問があります。Gearmanとタスク実行のためにinotify
多くのファイルが保存され、処理されるフォルダ(1時間あたり1000以上)を監視するために、inotifyを使用しています。 ギアマンを使用しようとしているデータベースにそれぞれの内容を解析し、その内容を保存します。
<?php
namespace controllers;
use app\file\File;
require_once 'vendor/autoload.php';
$worker = new \GearmanWorker();
$worker->addServer();
$worker->addFunction('parse_file', function($job){
echo "entrou no add function!<br>";
print_r ($job->workload());
sleep(2);
return new File($job->workload()); # this class parses the files content in database
});
while ($worker->work());
物事が今起こっている:
while(true){
sleep(5); # spare some CPU Cycles
set_time_limit(0); # unlimited timeout request
// read events
$events = inotify_read($this->instance);
// if the event is happening within our 'Files directory'
if ($events[0]['wd'] === $this->watch_id){
foreach ($events as $key=>$value)
{
if($events[$key]['mask'] === IN_CREATE){
# A new file was created in folder
$client = new \GearmanClient();
$client->addServer();
$client->addTask("parse_file", $events[$key]['name']); # add task to parse that file
printf("Created file: %s in Files directory\n", $events[$key]['name']);
}
else if ($events[$key]['mask'] === IN_DELETE){
printf("Deleted file: %s in Files directory\n", $events[$key]['name']);
}
}
if(!is_null($client)){ # once everything is done, run the tasks.
$client->runTasks();
}
}
}
は、私はこのようなworker.phpファイルを作成しました。ワーカー関数が実行され、最初のファイルのデータがデータベースに格納されますが、エラーが発生します。
これは、nohup.outファイルの出力です。
Catchable fatal error: Object of class app\file\File could not be converted to string in /var/www/html/worker.php on line 18
「彼」は何を望みますか? :)