PHP code example of exfriend / cloudfactory

1. Go to this page and download the library: Download exfriend/cloudfactory 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/ */

    

exfriend / cloudfactory example snippets




ne = new \Exfriend\CloudFactory\Engine();
$request = new \Exfriend\CloudFactory\Request('http://httpbin.org/get');
$engine->run($request);

print_r($request->response);

$request = (new \Exfriend\CloudFactory\Request('http://httpbin.org/get'))->setOpt(CURLOPT_FOLLOWLOCATION, true);

$engine = (new \Exfriend\CloudFactory\Engine())->setThreads(25);

for ($i = 0; $i < 100; $i++) {
    $request = new \Exfriend\CloudFactory\Request('http://httpbin.org/get?i=' . $i);
    $engine->addRequest($request);
}

$engine->run();

foreach ($engine->requests->processed() as $request) {
    print_r($request->response);
}

$request = (new Request('http://httpbin.org/get'))
    ->maxTries(3)
    ->store('i', $i)// to pass through to the callback
    ->validateUsing(function (Request $request) { // using closure
        // must return boolean
        return strpos($request->response, 'origin') !== false;
    })
    ->onSuccess('request_success')// using string
    ->onSuccess(function ($r) {
        echo 'You can stack callbacks of one type' . PHP_EOL;
    })
    ->onFail(function ($r) {
        echo "Request failed {$r->tries_current} times of {$r->tries_max}: " . $r->url;
    })
    ->onLastFail(function ($r) {
        echo "Request failed last time: " . $r->url;
    });

...
  ->store( 'user', $user )
  ->onSuccess(function($request)){
      $user = $request->storage->get('user');
  })
...