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


PHP Client::getAsync方法代码示例

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


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

示例1: getAllProjects

 public function getAllProjects()
 {
     $key = "{$this->cachePrefix}-all-projects";
     if ($this->cache && ($projects = $this->cache->fetch($key))) {
         return $projects;
     }
     $first = json_decode($this->client->get('projects.json', ['query' => ['limit' => 100]])->getBody(), true);
     $projects = $first['projects'];
     if ($first['total_count'] > 100) {
         $requests = [];
         for ($i = 100; $i < $first['total_count']; $i += 100) {
             $requests[] = $this->client->getAsync('projects.json', ['query' => ['limit' => 100, 'offset' => $i]]);
         }
         /** @var Response[] $responses */
         $responses = Promise\unwrap($requests);
         $responseProjects = array_map(function (Response $response) {
             return json_decode($response->getBody(), true)['projects'];
         }, $responses);
         $responseProjects[] = $projects;
         $projects = call_user_func_array('array_merge', $responseProjects);
     }
     usort($projects, function ($projectA, $projectB) {
         return strcasecmp($projectA['name'], $projectB['name']);
     });
     $this->cache && $this->cache->save($key, $projects);
     return $projects;
 }
开发者ID:stelsvitya,项目名称:server-manager,代码行数:27,代码来源:Projects.php

示例2: __invoke

 /**
  * __invoke.
  *
  * @param mixed $values
  *
  * @return $this
  */
 public function __invoke($values)
 {
     $response = json_decode((string) $values->getBody());
     // Return when empty response.
     if (empty($response)) {
         return $this;
     }
     // Process the response.
     $this->process($response);
     $promisses = [];
     // Loop over all artist and create promisses
     foreach ($this->getArtistsAlbumsList() as $artistEntity) {
         $artistEntity = $artistEntity[0];
         // Process offset value only one time.
         if (isset($this->processedArtistsList[$artistEntity->id]) && $this->processedArtistsList[$artistEntity->id] === true) {
             continue;
         } else {
             $getArtistRelatedArtists = 'artists/' . $artistEntity->id . '/related-artists';
             $promisses[] = $this->client->getAsync($getArtistRelatedArtists)->then($this);
             // <= re-use same object.
             $this->processedArtistsList[$artistEntity->id] = true;
         }
     }
     // Resolve promisses.
     Promise\unwrap($promisses);
     return $this;
 }
开发者ID:websoftwares,项目名称:spotify-artist-album-overview,代码行数:34,代码来源:ArtistsHandler.php

示例3: getAsync

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

示例4: getArtistsAndAlbumsByIdList

 /**
  * Returns a list of artist entities.
  *
  * @param array $artistIdList list of spotify id's.
  *
  * @return ArtistsAlbumsList
  */
 public function getArtistsAndAlbumsByIdList(array $artistIdList = [])
 {
     if (empty($artistIdList)) {
         throw new \InvalidArgumentException('Artist id list is empty.');
     }
     $getSeveralArtists = 'artists?ids=' . implode(',', $artistIdList);
     $rejectHandler = HandlerFactory::newRejectHandlerInstance();
     $promise = $this->client->getAsync($getSeveralArtists)->then(HandlerFactory::newArtistHandlerInstance($this->client), $rejectHandler)->then(HandlerFactory::newAlbumsHandlerInstance($this->client), $rejectHandler);
     $response = $promise->wait();
     return $response->getArtistsAlbumsList();
 }
开发者ID:websoftwares,项目名称:spotify-artist-album-overview,代码行数:18,代码来源:SpotifyClient.php

示例5: watchConcurrent

 /**
  * Get loading time information for two websites
  * Info: Requests are concurrent - http://docs.guzzlephp.org/en/latest/quickstart.html#concurrent-requests
  *
  * @param $comparingUri
  * @param $competitorUri
  *
  * @return array
  */
 public function watchConcurrent($comparingUri, $competitorUri)
 {
     $comparingStats = null;
     $comparingRequest = $this->client->getAsync($comparingUri, [RequestOptions::TIMEOUT => $this->timeout, RequestOptions::ON_STATS => function (TransferStats $stats) use(&$comparingStats) {
         $comparingStats = $stats;
     }]);
     $competitorStats = null;
     $competitorRequest = $this->client->getAsync($competitorUri, [RequestOptions::TIMEOUT => $this->timeout, RequestOptions::ON_STATS => function (TransferStats $stats) use(&$competitorStats) {
         $competitorStats = $stats;
     }]);
     Promise\settle([$comparingRequest, $competitorRequest])->wait();
     return [$comparingStats, $competitorStats];
 }
开发者ID:pwlap,项目名称:loater,代码行数:22,代码来源:Timer.php

示例6: __invoke

 /**
  * __invoke.
  *
  * @param mixed $values
  *
  * @return $this
  */
 public function __invoke($values)
 {
     // Get from previous handler the artists albums list.
     $this->artistsAlbumsList = $values->getArtistsAlbumsList();
     $promisses = [];
     // Loop over the artists albums list creating promisses for each artist.
     foreach ($this->artistsAlbumsList as $artistId => $artistAlbum) {
         $artistsTopTracks = 'artists/' . $artistId . '/top-tracks?country=US';
         $promisses[$artistId] = $this->client->getAsync($artistsTopTracks);
     }
     // Resolve all promisses.
     $artistAlbums = Promise\unwrap($promisses);
     // Process the result.
     $this->process($artistAlbums);
     return $this;
 }
开发者ID:websoftwares,项目名称:spotify-artist-album-overview,代码行数:23,代码来源:AlbumsHandler.php

示例7: http

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

示例8: handle

 public function handle()
 {
     $this->totalPageCount = count($this->users);
     $client = new Client();
     $requests = function ($total) use($client) {
         foreach ($this->users as $key => $user) {
             $uri = 'https://api.github.com/users/' . $user;
             (yield function () use($client, $uri) {
                 return $client->getAsync($uri);
             });
         }
     };
     $pool = new Pool($client, $requests($this->totalPageCount), ['concurrency' => $this->concurrency, 'fulfilled' => function ($response, $index) {
         $res = json_decode($response->getBody()->getContents());
         $this->info("请求第 {$index} 个请求,用户 " . $this->users[$index] . " 的 Github ID 为:" . $res->id);
         $this->countedAndCheckEnded();
     }, 'rejected' => function ($reason, $index) {
         $this->error("rejected");
         $this->error("rejected reason: " . $reason);
         $this->countedAndCheckEnded();
     }]);
     // 开始发送请求
     $promise = $pool->promise();
     $promise->wait();
 }
开发者ID:qloog,项目名称:laravel5-backend,代码行数:25,代码来源:MultithreadingRequest.php

示例9: getCo2Ppm

 /**
  * @return \GuzzleHttp\Promise\PromiseInterface
  */
 public function getCo2Ppm()
 {
     return $this->http->getAsync('query', [RequestOptions::AUTH => [$this->influxConfig->user, $this->influxConfig->password], RequestOptions::QUERY => ['db' => 'air', 'q' => 'select last(ppm) from co2']])->then(function (ResponseInterface $response) {
         $influxResponse = json_decode($response->getBody(), true);
         /*
            {
                "results": [
                    {
                        "series": [
                            {
                                "name": "cpu_load_short",
                                "columns": [
                                    "time",
                                    "ppm"
                                ],
                                "values": [
                                    [
                                        "2015-01-29T21:55:43.702900257Z",
                                        0.55
                                    ],
                                    [
                                        "2015-01-29T21:55:43.702900257Z",
                                        23422
                                    ],
                                    [
                                        "2015-06-11T20:46:02Z",
                                        0.64
                                    ]
                                ]
                            }
                        ]
                    }
                ]
            }
         */
         if (!$influxResponse || !is_array($influxResponse)) {
             return null;
         }
         return $influxResponse['results'][0]['series'][0]['values'][0][1];
     }, function ($e) {
         // todo logging
         var_dump($e->getMessage());
         //                echo $e->getMessage() . "\n";
         //                echo $e->getRequest()->getMethod();
     });
 }
开发者ID:melfa,项目名称:air-telegram-bot,代码行数:49,代码来源:Storage.php

示例10: findVulnerabilities

 /**
  * @param $entities
  *
  * @return mixed
  */
 private function findVulnerabilities(array $entities)
 {
     $requests = Collection::make($entities)->map(function (Entity $entity) {
         return function () use($entity) {
             return $this->vulnDBApi->getAsync($this->getAPIPath($entity));
         };
     })->getIterator();
     (new Pool($this->vulnDBApi, $requests, ['concurrency' => $this->config->get('http.concurrency'), 'fulfilled' => function ($response, $index) use(&$entities) {
         if ($response->getStatusCode() === 200) {
             $response_object = json_decode((string) $response->getBody());
             if ($this->isVulnerable($response_object, $entities[$index], $vulnerabilities)) {
                 $entities[$index]->vulnerable(Collection::make($vulnerabilities)->implode('title', ','));
             }
         }
     }]))->promise()->wait();
     return $entities;
 }
开发者ID:Zae,项目名称:wp-vulnerabilities,代码行数:22,代码来源:VulnDB.php

示例11: applyToNode

 /**
  * Do async request for node
  * 
  * @param Node $node
  */
 public function applyToNode(Node $node)
 {
     $url = $this->getUrl($node);
     if (!isset($url)) {
         return;
     }
     $client = new Client(['http_errors' => false]);
     $promise = $client->getAsync($url)->then(function (Response $response) use($node) {
         $this->applyResult($node, $response);
     });
     $node->setResult($promise);
 }
开发者ID:legalthings,项目名称:data-enricher,代码行数:17,代码来源:Http.php

示例12: testCanSendMagicAsyncRequests

 public function testCanSendMagicAsyncRequests()
 {
     $client = new Client();
     Server::flush();
     Server::enqueue([new Response(200, ['Content-Length' => 2], 'hi')]);
     $p = $client->getAsync(Server::$url, ['query' => ['test' => 'foo']]);
     $this->assertInstanceOf(PromiseInterface::class, $p);
     $this->assertEquals(200, $p->wait()->getStatusCode());
     $received = Server::received(true);
     $this->assertCount(1, $received);
     $this->assertEquals('test=foo', $received[0]->getUri()->getQuery());
 }
开发者ID:nystudio107,项目名称:instantanalytics,代码行数:12,代码来源:ClientTest.php

示例13: flushPromises

 /**
  * @return array
  */
 private function flushPromises()
 {
     foreach ($this->queries as $key => $query) {
         $cacheKey = $query->getCacheKey();
         // checks if cache exists for the requests. if not pass it to promise.
         if (!($cacheKey && ($cacheItem = $this->getCachePool()->getItem($cacheKey)) && $cacheItem->isHit())) {
             ++$this->debug['executedqueries'];
             $this->promises[$key] = $this->client->getAsync((string) $query);
         } elseif ($cacheKey) {
             $this->cacheData[$key] = $cacheItem->get();
         }
         unset($this->queries[$key]);
     }
     return $this->promises;
 }
开发者ID:bureau-va,项目名称:wordpress-guzzle-wrapper,代码行数:18,代码来源:Pool.php

示例14: fetchAccountsPresence

 public function fetchAccountsPresence($accounts)
 {
     $client = new GuzzleClient(['base_uri' => XboxConstants::$getBaseXboxAPI]);
     // Set up getCommands
     $requests = array();
     foreach ($accounts as $account) {
         if ($account->xuid == null) {
             $destiny = new DestinyClient();
             $account = $destiny->fetchAccountData($account);
         }
         $url = sprintf(XboxConstants::$getPresenceUrl, $account->xuid);
         $requests[$account->seo] = $client->getAsync($url, ['headers' => ['X-AUTH' => env('XBOXAPI_KEY')]]);
     }
     $results = GuzzlePromise\Unwrap($requests);
     return $results;
 }
开发者ID:GMSteuart,项目名称:PandaLove,代码行数:16,代码来源:Client.php

示例15: search

 private function search()
 {
     // https://oeis.org/search?q=1010&sort=&language=english&go=Search
     $client = new Client(['base_uri' => 'https://oeis.org', 'cookies' => true]);
     for ($i = 0; $i < 1000000; $i++) {
         $a = function ($number) use($client) {
             return $client->getAsync('/search', ['query' => ['q' => $number, 'language' => 'english', 'go' => 'Search']])->then(function (Response $response) use($number) {
                 $content = $response->getBody()->getContents();
                 preg_match('/of (\\d+) results|Found (\\d+) results/', $content, $matches);
                 $found = $matches[1] ? $matches[1] : ($matches[2] ? $matches[2] : 0);
                 return [$number, $found];
             });
         };
         (yield $a($i));
     }
 }
开发者ID:mcfedr,项目名称:popular-numbers,代码行数:16,代码来源:AppNumbersCommand.php


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