当前位置: 首页>>代码示例>>PHP>>正文


PHP Client::sendAsync方法代码示例

本文整理汇总了PHP中GuzzleHttp\Client::sendAsync方法的典型用法代码示例。如果您正苦于以下问题:PHP Client::sendAsync方法的具体用法?PHP Client::sendAsync怎么用?PHP Client::sendAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在GuzzleHttp\Client的用法示例。


在下文中一共展示了Client::sendAsync方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: addReValidationRequest

 /**
  * @param RequestInterface       $request
  * @param CacheStrategyInterface $cacheStorage
  * @param CacheEntry             $cacheEntry
  *
  * @return bool if added
  */
 protected function addReValidationRequest(RequestInterface $request, CacheStrategyInterface &$cacheStorage, CacheEntry $cacheEntry)
 {
     // Add the promise for revalidate
     if ($this->client !== null) {
         /** @var RequestInterface $request */
         $request = $request->withHeader(self::HEADER_RE_VALIDATION, '1');
         $this->waitingRevalidate[] = $this->client->sendAsync($request)->then(function (ResponseInterface $response) use($request, &$cacheStorage, $cacheEntry) {
             $update = false;
             if ($response->getStatusCode() == 304) {
                 // Not modified => cache entry is re-validate
                 /** @var ResponseInterface $response */
                 $response = $response->withStatus($cacheEntry->getResponse()->getStatusCode());
                 $response = $response->withBody($cacheEntry->getResponse()->getBody());
                 // Merge headers of the "304 Not Modified" and the cache entry
                 foreach ($cacheEntry->getResponse()->getHeaders() as $headerName => $headerValue) {
                     if (!$response->hasHeader($headerName)) {
                         $response = $response->withHeader($headerName, $headerValue);
                     }
                 }
                 $update = true;
             }
             self::addToCache($cacheStorage, $request, $response, $update);
         });
         return true;
     }
     return false;
 }
开发者ID:kevinrob,项目名称:guzzle-cache-middleware,代码行数:34,代码来源:CacheMiddleware.php

示例2: notify

 /**
  * @param mixed $data
  */
 public function notify($data)
 {
     $client = new Client();
     $request = new Request('POST', $this->webhookUrl, ['Content-type' => 'application/json'], json_encode($data));
     $promise = $client->sendAsync($request, ['timeout' => 10]);
     $promise->then(function (ResponseInterface $res) use($data) {
         $this->logger->info(sprintf('Request to SLACK webhook OK [%s] with data: %s', $res->getStatusCode(), json_encode($data)));
     }, function (RequestException $e) {
         $this->logger->error(sprintf('Request to SLACK webhook FAILED with message: %s', $e->getMessage()));
     });
     $promise->wait(false);
 }
开发者ID:akeneo,项目名称:badger,代码行数:15,代码来源:SlackNotifier.php

示例3: __construct

 public function __construct()
 {
     // call parent constructor
     parent::__construct();
     // create the asyncronous curl handler
     $this->handler = new CurlMultiHandler();
     $httpClient = new Client(['handler' => HandlerStack::create($this->handler)]);
     // have the request wrapper call guzzle asyncronously
     $this->setRequestWrapper(new RequestWrapper(['scopes' => PubSubClient::FULL_CONTROL_SCOPE, 'httpHandler' => function ($request, $options = []) use($httpClient) {
         return $httpClient->sendAsync($request, $options);
     }, 'authHttpHandler' => HttpHandlerFactory::build()]));
 }
开发者ID:GoogleCloudPlatform,项目名称:getting-started-php,代码行数:12,代码来源:AsyncConnection.php

示例4: sendRequest

 /**
  * @param RpcRequest $rpcRequest
  * @param string     $resultType
  *
  * @return RpcResponse|null
  */
 protected function sendRequest(RpcRequest $rpcRequest, $resultType = null)
 {
     try {
         $request = $this->convertRequest($rpcRequest);
         if (!$this->synchronous) {
             $this->client->sendAsync($request);
             return;
         }
         $response = $this->client->send($request);
     } catch (ServerException $ex) {
         $response = $ex->getResponse();
     } catch (ClientException $ex) {
         $response = $ex->getResponse();
     }
     $rpcResponse = $this->convertResponse($response, $resultType);
     return $rpcResponse;
 }
开发者ID:mihai-stancu,项目名称:rpc-bundle,代码行数:23,代码来源:HttpConnection.php

示例5: addReValidationRequest

 /**
  * @param RequestInterface       $request
  * @param CacheStrategyInterface $cacheStorage
  * @param CacheEntry             $cacheEntry
  *
  * @return bool if added
  */
 protected function addReValidationRequest(RequestInterface $request, CacheStrategyInterface &$cacheStorage, CacheEntry $cacheEntry)
 {
     // Add the promise for revalidate
     if ($this->client !== null) {
         /** @var RequestInterface $request */
         $request = $request->withHeader(self::HEADER_RE_VALIDATION, '1');
         $this->waitingRevalidate[] = $this->client->sendAsync($request)->then(function (ResponseInterface $response) use($request, &$cacheStorage, $cacheEntry) {
             if ($response->getStatusCode() == 304) {
                 // Not modified => cache entry is re-validate
                 /** @var ResponseInterface $response */
                 $response = $response->withStatus($cacheEntry->getResponse()->getStatusCode());
                 $response = $response->withBody($cacheEntry->getResponse()->getBody());
             }
             $cacheStorage->cache($request, $response);
         });
         return true;
     }
     return false;
 }
开发者ID:thedeedawg,项目名称:guzzle-cache-middleware,代码行数:26,代码来源:CacheMiddleware.php

示例6: addReValidationRequest

 /**
  * @param RequestInterface $request
  * @param CacheStorageInterface $cacheStorage
  * @param CacheEntry $cacheEntry
  * @return bool if added
  */
 protected static function addReValidationRequest(RequestInterface $request, CacheStorageInterface &$cacheStorage, CacheEntry $cacheEntry)
 {
     // Add the promise for revalidate
     if (static::$client !== null) {
         /** @var RequestInterface $request */
         $request = $request->withHeader("X-ReValidation", "1");
         static::$waitingRevalidate[] = static::$client->sendAsync($request)->then(function (ResponseInterface $response) use($request, &$cacheStorage, $cacheEntry) {
             if ($response->getStatusCode() == 304) {
                 // Not modified => cache entry is re-validate
                 /** @var ResponseInterface $response */
                 $response = $response->withStatus($cacheEntry->getResponse()->getStatusCode());
                 $response = $response->withBody($cacheEntry->getResponse()->getBody());
             }
             $cacheStorage->cache($request, $response);
         });
         return true;
     }
     return false;
 }
开发者ID:royopa,项目名称:guzzle-cache-middleware,代码行数:25,代码来源:CacheMiddleware.php

示例7: testCanRetryExceptions

 public function testCanRetryExceptions()
 {
     $calls = [];
     $decider = function ($retries, $request, $response, $error) use(&$calls) {
         $calls[] = func_get_args();
         return $error instanceof \Exception;
     };
     $m = Middleware::retry($decider);
     $h = new MockHandler([new \Exception(), new Response(201)]);
     $c = new Client(['handler' => $m($h)]);
     $p = $c->sendAsync(new Request('GET', 'http://test.com'), []);
     $this->assertEquals(201, $p->wait()->getStatusCode());
     $this->assertCount(2, $calls);
     $this->assertEquals(0, $calls[0][0]);
     $this->assertNull($calls[0][2]);
     $this->assertInstanceOf('Exception', $calls[0][3]);
     $this->assertEquals(1, $calls[1][0]);
     $this->assertInstanceOf(Response::class, $calls[1][2]);
     $this->assertNull($calls[1][3]);
 }
开发者ID:nystudio107,项目名称:instantanalytics,代码行数:20,代码来源:RetryMiddlewareTest.php

示例8: sendRequest

 /**
  * Send our request to Guzzle and process the result
  *
  * @param Request $ourRequest
  * @param Client $client
  * @return \GuzzleHttp\Promise\PromiseInterface
  */
 protected function sendRequest(Request $ourRequest, Client $client)
 {
     $ourRequest->processed = false;
     $ourRequest->processing = true;
     $request = new GuzzleRequest($ourRequest->options->get(CURLOPT_POSTFIELDS, false) ? 'POST' : 'GET', $ourRequest->url);
     $promise = $client->sendAsync($request, ['curl' => $ourRequest->options->get()])->then(function ($response) use($client, $ourRequest) {
         $body = (string) $response->getBody();
         $ourRequest->response = $body;
         $ourRequest->error = false;
         if ($ourRequest->remote_encoding) {
             $ourRequest->response = mb_convert_encoding($ourRequest, 'UTF-8', $ourRequest->remote_encoding);
         }
         $this->handleProcessedRequest($client, $ourRequest);
     }, function ($error) use($client, $ourRequest) {
         $ourRequest->error = $error;
         $this->handleProcessedRequest($client, $ourRequest);
     });
     return $promise;
 }
开发者ID:exfriend,项目名称:cloudfactory,代码行数:26,代码来源:Engine.php

示例9: executeAsync

 /**
  * @param Request $command
  * @param array   $operation
  *
  * @return bool
  */
 public function executeAsync(Request $command, $operation)
 {
     $client = new Client();
     $client->sendAsync($command)->then(function ($response) {
     })->wait();
     return true;
 }
开发者ID:instela,项目名称:instela-php-sdk,代码行数:13,代码来源:InstelaClient.php

示例10: sendAsync

 /**
  * @inheritDoc
  */
 public function sendAsync(RequestInterface $request, array $options = [])
 {
     return $this->client->sendAsync($request, $options);
 }
开发者ID:audiens,项目名称:appnexus-client,代码行数:7,代码来源:Auth.php

示例11: toApi

 public function toApi(Request $request)
 {
     $client = new \GuzzleHttp\Client();
     $input = $request::all();
     $command = 'request';
     $api_key = 'MjuhMtfAAfvJqzbnWFLA';
     // $api_key = 'mysendykey';
     $api_username = 'chris';
     // $api_username = 'mysendyusername';
     $from_name = 'Chris Munialo';
     $from_lat = $input['lat'];
     $from_long = $input['lng'];
     $from_description = '';
     $to_name = 'Thika Road Mall';
     $to_lat = $input['lat1'];
     $to_long = $input['lng1'];
     $to_description = '';
     $recepient_name = 'John Doe';
     $recepient_phone = '0710000000';
     $recepient_email = 'John@doe.com';
     $pick_up_date = '2016-04-20 12:12:12';
     $status = false;
     $pay_method = 0;
     $amount = 10;
     $return = true;
     $note = 'Sample note';
     $note_status = true;
     $request_type = 'delivery';
     $info = ['command' => $command, 'data' => ['api_key' => $api_key, 'api_username' => $api_username, 'from' => ['from_name' => $from_name, 'from_lat' => $from_lat, 'from_long' => $from_long, 'from_description' => $from_description], 'to' => ['to_name' => $to_name, 'to_lat' => $to_lat, 'to_long' => $to_long, 'to_description' => $to_description], 'recepient' => ['recepient_name' => $recepient_name, 'recepient_phone' => $recepient_phone, 'recepient_email' => $recepient_email], 'delivery_details' => ['pick_up_date' => $pick_up_date, 'collect_payment' => ['status' => $status, 'pay_method' => $pay_method, 'amount' => $amount], 'return' => $return, 'note' => $note, 'note_status' => $note_status, 'request_type' => $request_type]]];
     $clientHandler = $client->getConfig('handler');
     // Create a middleware that echoes parts of the request.
     $tapMiddleware = Middleware::tap(function ($request) {
         $request->getHeader('Content-Type');
         // application/json
         echo $request->getBody();
         // {"foo":"bar"}
     });
     $endpoint = 'https://developer.sendyit.com/v1/api#request';
     // $info = json_encode($info);
     $client = new \GuzzleHttp\Client();
     $res = $client->request('POST', $endpoint, ['json' => $info, 'handler' => $tapMiddleware($clientHandler)]);
     $res->getStatusCode();
     // "200"
     $res->getHeader('content-type');
     // 'application/json; charset=utf8'
     $res->getBody();
     // {"type":"User"...
     // Send an asynchronous request.
     $request = new \GuzzleHttp\Psr7\Request('GET', $endpoint);
     $promise = $client->sendAsync($request)->then(function ($response) {
         echo 'I completed! ' . $response->getBody();
     });
     $promise->wait();
     return view('orders.new', compact($res));
 }
开发者ID:krysmunialo,项目名称:Request-Package-Delivery,代码行数:55,代码来源:OrdersController.php

示例12: exec

 /**
  * @inheritDoc
  */
 public function exec(RequestInterface $request)
 {
     return $this->client->sendAsync($request);
 }
开发者ID:alekitto,项目名称:api-connector-bundle,代码行数:7,代码来源:GuzzleTransport.php

示例13: send

 /**
  * @param Client $client
  * @param Request $request
  * @return PromiseInterface
  */
 protected function send(Client $client, Request $request)
 {
     $promise = $client->sendAsync($request)->then([$this, 'handleSuccess'], [$this, 'handleError']);
     return $promise;
 }
开发者ID:thisdata,项目名称:thisdata-php,代码行数:10,代码来源:AbstractRequestHandler.php


注:本文中的GuzzleHttp\Client::sendAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。