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


PHP Client::postAsync方法代码示例

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


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

示例1: send

 /**
  * @inheritdoc
  */
 public function send()
 {
     $body = ['aps' => []];
     if ($this->messageData !== null) {
         $body['aps'] = $this->messageData;
     }
     if ($this->messageText !== null) {
         $body['aps']['alert'] = $this->messageText;
         if (!isset($body['aps']['sound'])) {
             $body['aps']['sound'] = 'default';
         }
         if (!isset($body['aps']['badge'])) {
             $body['aps']['badge'] = 0;
         }
     }
     $bodyData = json_encode($body);
     $ok = [];
     $promises = [];
     foreach ($this->recipients as $recipient) {
         $url = sprintf('/3/device/%s', $recipient);
         $promises[] = $this->client->postAsync($url, ['body' => $bodyData])->then(function (ResponseInterface $response) use(&$ok, $recipient) {
             if ($response->getStatusCode() == 200) {
                 // Set to OK if we received a 200
                 $ok[] = $recipient;
             } else {
                 $this->failedRecipients[] = $recipient;
             }
         }, function () use($recipient) {
             $this->failedRecipients[] = $recipient;
         });
     }
     // Wait for all requests to complete
     Promise\unwrap($promises);
     return $ok;
 }
开发者ID:pharmit,项目名称:push,代码行数:38,代码来源:ApplePushService.php

示例2: __invoke

 /**
  * @inheritdoc
  */
 public function __invoke(Message $message, Deferred $deferred = null)
 {
     $messageData = $this->messageConverter->convertToArray($message);
     MessageDataAssertion::assert($messageData);
     $messageData['created_at'] = $message->createdAt()->format('Y-m-d\\TH:i:s.u');
     $promise = $this->guzzleClient->postAsync($this->uri, ['json' => $messageData]);
     if ($deferred) {
         if ($this->async) {
             $this->resolveOrRejectDeferredAsync($deferred, $promise);
         } else {
             $this->resolveOrRejectDeferredSync($deferred, $promise);
         }
     }
 }
开发者ID:prooph,项目名称:psb-http-producer,代码行数:17,代码来源:HttpMessageProducer.php

示例3: postAsync

 /**
  * @param string $uri
  * @param array  $body
  * @param array  $options
  *
  * @return Promise
  */
 public function postAsync($uri, array $body = [], array $options = [])
 {
     if (!empty($body)) {
         $options['json'] = $body;
     }
     return $this->guzzle->postAsync($uri, $options);
 }
开发者ID:jacobemerick,项目名称:php-shutterstock-api,代码行数:14,代码来源:Client.php

示例4: slack

 static function slack()
 {
     return function ($log_entry, $options) {
         $client = new Client();
         $url = $options;
         if (is_array($options)) {
             if (!isset($options['url'])) {
                 throw new \LogicException('Slack requires either a string(url) or an array of options with the key url to be set to CURL');
             }
             $url = $options['url'];
         }
         $client->postAsync($url, array('body' => json_encode(array('text' => strtoupper($log_entry['level']['text']) . ': ' . $log_entry['msg']))));
     };
 }
开发者ID:kcmerrill,项目名称:snitchin,代码行数:14,代码来源:snitches.php

示例5: send

 /**
  * @inheritdoc
  */
 public function send()
 {
     $body = ['data' => []];
     if ($this->messageData !== null) {
         $body['data'] = $this->messageData;
     }
     if ($this->messageText !== null) {
         $body['data']['message'] = $this->messageText;
     }
     $ok = [];
     $promises = [];
     $recipients_chunked = array_chunk($this->recipients, 1000);
     foreach ($recipients_chunked as $recipients_part) {
         $body['registration_ids'] = $recipients_part;
         $promises[] = $this->client->postAsync('/gcm/send', ['body' => json_encode($body)])->then(function (ResponseInterface $response) use(&$ok, $recipients_part) {
             if ($response->getStatusCode() == 200) {
                 // Set to OK if we received a 200
                 $contents = json_decode($response->getBody()->getContents(), true);
                 $results = $contents['results'];
                 foreach ($recipients_part as $idx => $recipient) {
                     if (isset($results[$idx]['message_id']) && !isset($results[$idx]['error'])) {
                         $ok[] = $recipient;
                     } else {
                         $this->failedRecipients[] = $recipient;
                     }
                 }
             }
         }, function () use($recipients_part) {
             foreach ($recipients_part as $idx => $recipient) {
                 $this->failedRecipients[] = $recipient;
             }
         });
     }
     // Wait for all requests to complete
     Promise\unwrap($promises);
     return $ok;
 }
开发者ID:pharmit,项目名称:push,代码行数:40,代码来源:GooglePushService.php

示例6: callWebhooks

 /**
  * Call all webhooks asynchronous
  *
  * @param array $webhooks
  * @param       $eventData
  */
 private function callWebhooks($webhooks, $eventData)
 {
     foreach ($webhooks as $webhook) {
         $this->client->postAsync($webhook["url"], ["body" => json_encode($this->createRequestBody($eventData)), "verify" => false]);
     }
 }
开发者ID:sschlein,项目名称:captainhook,代码行数:12,代码来源:CaptainHookServiceProvider.php

示例7: function

require __DIR__ . '/vendor/autoload.php';
use GuzzleHttp\Client;
use GuzzleHttp\TransferStats;
use GuzzleHttp\HandlerStack;
$stats = function (TransferStats $stats) {
    echo $stats->getTransferTime() . " " . $stats->getEffectiveUri() . "\n";
};
// if you are going to use multiple clients, and want to make requests async among all of them
// you have to pass a handler into the client, so they all run in the same loop
$handler = HandlerStack::create();
$usernameClient = new Client(['base_uri' => 'http://localhost:8000/', 'timeout' => 10, 'on_stats' => $stats, 'handler' => $handler]);
$passwordClient = new Client(['base_uri' => 'http://localhost:8001/', 'timeout' => 10, 'on_stats' => $stats, 'handler' => $handler]);
$emailClient = new Client(['base_uri' => 'http://localhost:8002/', 'timeout' => 10, 'on_stats' => $stats, 'handler' => $handler]);
$start = microtime(true);
$username1 = $usernameClient->post('generate-username');
$username2 = $usernameClient->post('generate-username');
$password = $passwordClient->post('generate-password');
$email = $emailClient->post('generate-email');
$stop = microtime(true);
$time = $stop - $start;
echo "4 requests in {$time} seconds\n";
$start = microtime(true);
$promises = [];
$promises['username1'] = $usernameClient->postAsync('generate-username');
$promises['username2'] = $usernameClient->postAsync('generate-username');
$promises['password'] = $passwordClient->postAsync('generate-password');
$promises['email'] = $emailClient->postAsync('generate-email');
$results = GuzzleHttp\Promise\unwrap($promises);
$stop = microtime(true);
$time = $stop - $start;
echo "4 requests in {$time} seconds\n";
开发者ID:azPHP,项目名称:guzzle-async-demo,代码行数:31,代码来源:5-async-timing.php


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