Where does PDO object fits best when the worker is a long running process. It is having the problem with MySQL server has gone away http://dev.mysql.com/doc/refman/5.1/en/gone-away.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // Reverse Client Code | |
| $client= new GearmanClient(); | |
| $client->addServer("127.0.0.1", "4730"); | |
| $data = array( | |
| 'something' => rand(1, 1000), | |
| ); | |
| $client->setCompleteCallback(function ($task) { | |
| print "COMPLETE: " . $task->unique() . ", " . $task->data() . "\n"; | |
| }); | |
| $client->setFailCallback(function ($task) { | |
| print "Failed: " . $task->unique() . ", " . $task->data() . "\n"; | |
| }); | |
| $client->addTaskBackground('reverse', json_encode($data)); | |
| $client->addTask('reverse', json_encode(array())); | |
| $client->addTaskBackground('reverse', json_encode($data)); | |
| $client->runTasks(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // Reverse worker Code | |
| $worker= new GearmanWorker(); | |
| $worker->addServer("127.0.0.1", "4730"); | |
| $worker->addFunction("reverse", function ($job) { | |
| // use pdo here ? I feel no | |
| $pdo = new PDO(); | |
| $payload = json_decode($job->workload()); | |
| echo " Processing $payload->something" . PHP_EOL; | |
| if (! isset($payload->something)) { | |
| throw new Exception("Test whether things works! "); | |
| } | |
| return strrev($payload->something); | |
| }); | |
| while ($worker->work()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // Reverse worker Code | |
| $worker= new GearmanWorker(); | |
| $worker->addServer("127.0.0.1", "4730"); | |
| $pdo = new PDO() | |
| $worker->addFunction("reverse", function ($job) use ($pdo) { | |
| $payload = json_decode($job->workload()); | |
| echo " Processing $payload->something" . PHP_EOL; | |
| if (! isset($payload->something)) { | |
| throw new Exception("Test whether things works! "); | |
| } | |
| return strrev($payload->something); | |
| }); | |
| while ($worker->work()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment