setOption() публичный Метод

Set an individual Client option
public setOption ( integer $option, mixed $value ) : self
$option integer A Client option constant
$value mixed The option value to assign
Результат self
 private function getReactorAndAPI()
 {
     $reactor = \Amp\reactor();
     $cache = new NullResponseCache();
     $client = new ArtaxClient();
     $client->setOption(ArtaxClient::OP_MS_CONNECT_TIMEOUT, 5000);
     $client->setOption(ArtaxClient::OP_MS_KEEP_ALIVE_TIMEOUT, 1000);
     $githubAPI = new GithubService($client, $reactor, $cache, "Danack/test");
     return [$reactor, $githubAPI];
 }
Пример #2
0
            $this->urlsChecked[] = new URLResult($path, 500, "Error getting {$path} - " . $e->getMessage() . " Exception type is " . get_class($e));
        }
        if ($ok != true) {
            $this->errors++;
        }
    }
    /**
     * @return URLResult[]
     */
    function getResults()
    {
        return $this->urlsChecked;
    }
}
$site = "http://imagick.test";
$site = "http://phpimagick.com";
$site = "http://phpimagick.test";
$reactor = Amp\getReactor();
$client = new ArtaxClient();
$client->setOption(\Amp\Artax\Client::OP_MS_CONNECT_TIMEOUT, 2500);
$client->setOption(ArtaxClient::OP_HOST_CONNECTION_LIMIT, 4);
$siteChecker = new SiteChecker($site, $client);
$start = new URLToCheck('/', '/');
$siteChecker->checkURL($start);
$reactor->run();
echo "fin";
$printer = new HTMLPrinter($siteChecker->getResults(), $site);
$outputStream = fopen("./checkResults.html", "w");
$printer->output($outputStream);
fclose($outputStream);
echo "Check complete. Found " . $siteChecker->getURLCount() . " URIs with " . $siteChecker->getErrorCount() . " errors.";
Пример #3
0
<?php

use GithubService\GithubArtaxService\GithubService;
use ArtaxServiceBuilder\ResponseCache\NullResponseCache;
use Amp\Artax\Client as ArtaxClient;
use ArtaxServiceBuilder\BadResponseException;
use ArtaxServiceBuilder\Oauth2Token;
use GithubService\Hydrator\HydratorException;
require_once "testBootstrap.php";
$injector = createProvider();
$reactor = \Amp\reactor();
$cache = new NullResponseCache();
$client = new ArtaxClient();
$client->setOption(ArtaxClient::OP_MS_CONNECT_TIMEOUT, 5000);
$client->setOption(ArtaxClient::OP_MS_KEEP_ALIVE_TIMEOUT, 1000);
$githubAPI = new GithubService($client, $reactor, $cache, "Danack/test");
$token = @file_get_contents("../../GithubToken.txt");
$oauthToken = null;
if ($token) {
    $oauthToken = new Oauth2Token($token);
}
try {
    $tagListRequest = $githubAPI->listRepoTags(null, "Danack", "GithubArtaxService");
    $tagList = $tagListRequest->execute();
    foreach ($tagList as $tag) {
        /** @var $tag \GithubService\Model\Tag */
        printf("tag name %s, commmit %s \n", $tag->name, $tag->commit->sha);
    }
    $emojiResult = $githubAPI->listEmojis(null)->execute();
    foreach ($emojiResult->emojis as $emoji) {
        echo $emoji->name . " \n";
Пример #4
0
<?php

use Amp\Artax\Client;
require __DIR__ . '/../vendor/autoload.php';
try {
    // Instantiate the HTTP client
    $client = new Client();
    $client->setOption(Client::OP_VERBOSITY, Client::VERBOSE_ALL);
    // Let's build up a custom Request object
    $request = (new Amp\Artax\Request())->setMethod('POST')->setUri('http://httpbin.org/post')->setBody('zanzibar!');
    // Make an asynchronous HTTP request
    $promise = $client->request($request);
    // Client::request() is asynchronous! It doesn't return a response. Instead, it
    // returns a promise to resolve the response at some point in the future when
    // it's finished. Here we use the Amp concurrency framework to synchronously wait
    // for the eventual promise result.
    $response = \Amp\wait($promise);
    // Output the results
    printf("\nHTTP/%s %d %s\n\n------- RESPONSE BODY -------\n%s\n", $response->getProtocol(), $response->getStatus(), $response->getReason(), $response->getBody());
} catch (Amp\Artax\ClientException $e) {
    // If something goes wrong the Promise::wait() call will throw the relevant
    // exception. The Client::request() method itself will never throw.
    echo $e;
}
Пример #5
0
 public function testVerboseSend()
 {
     $uri = "http://httpbin.org/";
     $client = new Client();
     $client->setOption(Client::OP_VERBOSITY, Client::VERBOSE_SEND);
     $promise = $client->request($uri);
     $response = \Amp\wait($promise);
     $expectedLines = ["GET / HTTP/1.1", "Accept-Encoding: gzip, identity", "Host: httpbin.org", "User-Agent: " . Client::USER_AGENT, "Accept: */*"];
     $this->expectOutputString(implode("\r\n", $expectedLines) . "\r\n\r\n");
 }
Пример #6
0
 function prepareArtaxClient(ArtaxClient $client, Injector $provider)
 {
     $client->setOption(ArtaxClient::OP_MS_CONNECT_TIMEOUT, 25);
 }
Пример #7
0
 /**
  * Constructs a default HTTP client.
  *
  * @return Client
  */
 private function buildClient()
 {
     $client = new Client(new NullCookieJar());
     $client->setOption(Client::OP_DEFAULT_USER_AGENT, "kelunik/acme");
     return $client;
 }
Пример #8
0
 /**
  * Do the request (enabled multiple attempts)
  *
  * @param ArtaxMessage $request
  * @param int          $attempt
  *
  * @return ArtaxResponse|mixed
  * @throws AmpSocketException
  * @throws NbsockSocketException
  * @throws null
  */
 private function doRequest(ArtaxMessage $request, $attempt = 1)
 {
     $artaxClient = new ArtaxClient();
     $artaxClient->setOption(ArtaxClient::OP_MS_CONNECT_TIMEOUT, self::OP_MS_CONNECT_TIMEOUT);
     // connection timeout
     try {
         /** @var ArtaxResponse $ampResponse */
         $ampResponse = Amp\wait($artaxClient->request($request));
     } catch (\Exception $exception) {
         if ($exception instanceof AmpSocketException || $exception instanceof AmpResolutionException || $exception instanceof NbsockSocketException) {
             // try a second attempt
             if ($attempt < self::REQUEST_MAX_ATTEMPTS) {
                 return $this->doRequest($request, $attempt + 1);
             }
             // use seeds if we are offline (SocketException mean that we are offline)
             if ($seeds = $this->findSeeds()) {
                 return $seeds;
             }
         }
         throw $exception;
     }
     return $ampResponse;
 }
use Amp\Artax\Client as ArtaxClient;
use Amp\Artax\Response;
use ArtaxServiceBuilder\ResponseCache\NullResponseCache;
use GithubService\AuthToken\NullToken;
use GithubService\GithubArtaxService\GithubService;
use GithubService\Model\Tags;
// Create the appropriate Amp reactor for your system. This depends on
// which extensions you have loaded:
// uv extension -  UvReactor;
// libevent extension - LibeventReactor;
// otherwise a NativeReactor is used.
$reactor = \Amp\reactor();
$artaxClient = new ArtaxClient();
// The reactor keeps running while the socket is open. Set a short
// timeout to avoid waiting around too long
$artaxClient->setOption(\Amp\Artax\Client::OP_MS_KEEP_ALIVE_TIMEOUT, 1);
// Create the GithubService with the prepared client
$github = new GithubService($artaxClient, $reactor, new NullResponseCache(), 'Danack/GithubArtaxService');
//Get the first page of data
$command = $github->listRepoTags(new NullToken(), 'php', 'php-src');
$listRepoTagsCallback = function (Exception $exception = null, Tags $repoTags, Response $response = null) use($github) {
    if ($exception) {
        echo "An error occurred: " . $exception->getMessage();
        return;
    }
    echo "Tags on first page:\n";
    foreach ($repoTags as $repoTag) {
        echo "Found tag: " . $repoTag->name . "\n";
    }
    $pages = $repoTags->pager->getAllKnownPages();
    foreach ($pages as $page) {