Пример #1
-1
 /**
  * @param string[] $imageSrcs
  * @param bool $returnAll
  * @param Configuration $config
  *
  * @return object[]|null
  */
 private static function handleEntity($imageSrcs, $returnAll, $config)
 {
     $guzzle = new \GuzzleHttp\Client();
     $results = [];
     $requests = function ($urls) use($guzzle, $config, &$results) {
         foreach ($urls as $key => $url) {
             $file = tempnam(sys_get_temp_dir(), 'goose');
             $results[] = (object) ['url' => $url, 'file' => $file];
             (yield $key => function ($options) use($guzzle, $url, $file) {
                 $options['sink'] = $file;
                 return $guzzle->sendAsync(new \GuzzleHttp\Psr7\Request('GET', $url), $options);
             });
         }
     };
     $pool = new \GuzzleHttp\Pool($guzzle, $requests($imageSrcs), ['concurrency' => 25, 'fulfilled' => function ($response, $index) use(&$results, $returnAll) {
         if (!$returnAll && $response->getStatusCode() != 200) {
             unset($results[$index]);
         }
     }, 'rejected' => function ($reason, $index) use(&$results, $returnAll) {
         if ($returnAll) {
             $results[$index]->file = null;
         } else {
             unset($results[$index]);
         }
     }, 'options' => $config->get('browser')]);
     $pool->promise()->wait();
     if (empty($results)) {
         return null;
     }
     return $results;
 }
Пример #2
-1
 public function kirimSms($no_hp, $pesan)
 {
     $username = $this->username;
     $password = $this->password;
     $client = new \GuzzleHttp\Client();
     // Send an asynchronous request.
     $request = new \GuzzleHttp\Psr7\Request('GET', 'http://www.freesms4us.com/kirimsms.php?user='******'&pass='******'&no=' . $no_hp . '&isi=' . $pesan);
     $promise = $client->sendAsync($request)->then(function ($response) {
         // echo 'I completed! ' . $response->getBody();
         // \Log::info('pesan_sms : '.$response->getBody());
     });
     $promise->wait();
 }