Facebook
From Chunky Earthworm, 7 Years ago, written in PHP.
Embed
Download Paste or View Raw
Hits: 480
  1. <?php
  2.  
  3. require_once "vendor/autoload.php";
  4.  
  5. use GuzzleHttp\Client;
  6. use GuzzleHttp\Exception\RequestException;
  7. use GuzzleHttp\Psr7;
  8.  
  9. $threads = 10;
  10.  
  11. class Shared extends Threaded {}
  12.  
  13. class Atomic extends Threaded {
  14.     public function __construct() {
  15.         $this->value = 0;
  16.  
  17.         $this->client = new Client([
  18.             'base_uri' => 'http://otomoto.pl/',
  19.             'timeout'  => 5.0,
  20.         ]);
  21.  
  22.     }
  23.  
  24.     public function add($value) {
  25.         $this->value += $value;
  26.     }
  27.  
  28.     public function random(){
  29.         $this->random[] = rand(1,100);
  30.     }
  31.  
  32.     public $client;
  33.     protected $value;
  34.     public $random = array();
  35. }
  36.  
  37. class Work extends Threaded {
  38.     public function __construct(Shared $shared, Atomic $atomic) {
  39.         $this->shared = $shared;
  40.         $this->atomic = $atomic;
  41.     }
  42.  
  43.     public function run() {
  44.  
  45.         $client->request('GET', 'osobowe/toyota/', [
  46.             'query' => [
  47.                 'page' => '2'
  48.             ],
  49.  
  50.         ]);
  51.  
  52.  
  53.     }
  54.     protected $shared;
  55.     protected $atomic;
  56. }
  57.  
  58. $shared = new Shared();
  59. $atomic = new Atomic();
  60.  
  61. $pool = new Pool($threads);
  62.  
  63. for ($i = 0; $i < $threads; $i++)
  64.     $pool->submit(new Work($shared, $atomic));
  65.  
  66. $pool->shutdown();