PHP code example of oliverde8 / asynchronous-jobs

1. Go to this page and download the library: Download oliverde8/asynchronous-jobs library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

oliverde8 / asynchronous-jobs example snippets


class Sleep extends Job
{
    public $time = 1;

    /**
     * Method called by the new instance to run the job.
     *
     * @return mixed
     */
    public function run()
    {
        sleep($this->time);
    }

    /**
     * Method called by the original instance when the job has ran.
     *
     * @return mixed
     */
    public function end()
    {
      $time = $this->time;
      echo "I end after : $time!";
    }
}

$curlJob = new Curl();
$curlJob->setMethod('GET');
$curlJob->setUrl('http://jsonplaceholder.typicode.com/posts');

$curlJob->start();
JobRunner::getInstance()->waitForAll(1);

$info = $curlJob->getCurlInfo();
$response = $curlJob->getResponse()

public function testCallback()
{
    $curlJob = new CallbackCurl();
    $curlJob->setMethod('GET');
    $curlJob->setUrl('http://jsonplaceholder.typicode.com/posts');
    $curlJob->setCallback(array($this, '_testCallbackCallback'));

    $curlJob->start();
    JobRunner::getInstance()->waitForAll(1);
    echo "You should then see this !\n"
}

public function _testCallbackCallback(Job $curlJob)
{
    echo "You should first see this !\n";
}