Answer the question
In order to leave comments, you need to log in
How to catch asynchronous php?
Hello.
In general, I play around with the asynchronous execution of php code. The bottom line is ... There is a script, it refers to third-party web services. There are many services, their response time is different. If you synchronously execute each request to the web service, then it takes a lot of time ...
There is a library https://github.com/bucefal91/php-async from the respected https://habrahabr.ru/users/bucefal91/. Using this library, I make an asynchronous call to web services, something like this
$webservices=['service1', 'service2', 'service3']; //веб-сервисов может быть произвольное количество
$service=[];
foreach($webservices as $k=>$v){
$service[$v]=new ToolsAsyncResult('php index.php ' . $v); //делаем запрос к каждому сервису
}
//тут мы вызваем ассинхронный запрос
$foo=new ToolsAsyncResult('php index.php servicename' );
while($foo->isRunning()){
//крутим цикл пока не придет ответ от сервиса
}
$result=$foo->result(); //получаем результат и как то его обрабатываем
while($service[0]->isRunning() AND $service[1]->isRunning() AND $service[3]->isRunning()){
//крутим цикл пока не придет ответ от сервиса
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question