2

Actually, I am implementing a cron, where I need to call more than 50 APIs. So, I want to implement something like, if an API takes more than 10 seconds to call, I will skip that.

Actually, I am using PHP 5.6. I have tried to implement Round-Robin. I haven't got anything to check if an API takes more than 10 seconds to call.

1 Answers1

1

You can use ReactPHP tools for this purpose. Here examples how to work with timers https://blog.wyrihaximus.net/2015/01/reactphp-timers/

Example:

require 'vendor/autoload.php';

$loop = React\EventLoop\Factory::create();

$i = 0;
$loop->addPeriodicTimer(1, function(React\EventLoop\Timer\Timer $timer) use (&$i, $loop) {
    if ($i == 0) {
       // send request
    } elseif($i < 10){
       // check response
    } else {
        // cancel request and cancel timer
        $loop->cancelTimer($timer);
    }
    ++$i;
});

$loop->run();
potiev
  • 546
  • 2
  • 11