In complento the two answers above,
you can use German
+ reactPhp
with the gearman-async: "A async Gearman implementation for PHP ontop of reactphp"
Example of use:
<?php
use Gearman\Async\ClientInterface;
use Gearman\Async\Event\TaskDataEvent;
use Gearman\Async\TaskInterface;
use Gearman\Async\Factory;
require_once __DIR__ . "/../vendor/autoload.php";
// use default options
$factory = new Factory();
$factory->createClient("127.0.0.1", 4730)->then(
// on successful creation
function (ClientInterface $client) {
$client->submit("reverse", "Hallo Welt!")->then(function(TaskInterface $task) {
printf("Submitted: %s with \"%s\" [handle: %s]\n",
$task->getFunction(),
$task->getWorkload(),
$task->getHandle()
);
$task->on('complete', function (TaskDataEvent $event, ClientInterface $client) {
echo "Result: {$event->getData()}\n";
$client->disconnect();
});
});
},
// error-handler
function($error) {
echo "Error: $error\n";
}
);
$factory->getEventLoop()->run();
Did any of the answers help you? Or are there problems with them? Comment informing the author who doubts to try to use the proposed solution. If any of the answers solved your problem, mark it as correct by clicking on
– Guilherme Nascimento
PHP 7 already supports asynchronous programming.
– Filipe Moraes