PHP code example of teknasyon / guzzle-async-pool
1. Go to this page and download the library: Download teknasyon/guzzle-async-pool library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
teknasyon / guzzle-async-pool example snippets
// Soap servisinin wsdl dosyası
$wsdl = 'http://127.0.0.1:8080/soap_server.php?wsdl';
// Soap servis adresi
$endpoint = 'http://127.0.0.1:8080/soap_server.php';
// İstekte bulunulacak SoapAction bilgisi
$soapAction = 'http://tempuri.org/Multiply';
// İstekte bulunulacak fonksiyon adı.
$functionName = 'Multiply';
// İstekte bulunulacak fonksiyon için parametreler.
$functionParams = ['intA' => 10, 'intB' => 3];
$request = SoapRequestFactory::factory(
$wsdl,
$endpoint,
$soapAction,
$functionName,
$functionParams
);
$pool->onCompletedRequest(function ($index, RequestInterface $request, ResponseInterface $response) use ($startTime) {
$soapResponse = Decoder::decode($response->getBody()->getContents());
...
});
$pool->onFailedRequest(function ($index, RequestInterface $request, \Exception $exception) use ($startTime) {
$soapResponse = null;
if ($exception instanceof RequestException) {
$soapResponse = Decoder::decode($exception->getResponse()->getBody()->getContents());
}
...
});
bash
$ docker run -it --rm -v $(pwd):/app composer update
$ cd example
$ docker build -t testserver .
$ docker run -d -p 8080:80 -v $(pwd):/var/www/html testserver
$ php test.php
$ php test_guzzle_pool.php
$requests = [
SoapRequestFactory::factory(
'http://127.0.0.1:8080/soap_server.php?wsdl',
'http://127.0.0.1:8080/soap_server.php',
'http://tempuri.org/Add',
'Add',
['intA' => 10, 'intB' => 3]
),
SoapRequestFactory::factory(
'http://127.0.0.1:8080/soap_server.php?wsdl',
'http://127.0.0.1:8080/soap_server.php',
'http://tempuri.org/Subtract',
'Subtract',
['intA' => 10, 'intB' => 3]
),
SoapRequestFactory::factory(
'http://127.0.0.1:8080/soap_server.php?wsdl',
'http://127.0.0.1:8080/soap_server.php',
'http://tempuri.org/Multiply',
'Multiply',
['intA' => 10, 'intB' => 3]
)
];
$guzzlePoolSettings = ['concurrency' => 5];
$guzzleClient = new Client();
$pool = new Teknasyon\GuzzleAsyncPool\Pool($requests, $guzzlePoolSettings, $guzzleClient);
$pool->onCompletedRequest(function ($index, RequestInterface $request, ResponseInterface $response) {
});
$pool->onFailedRequest(function ($index, RequestInterface $request, \Exception $exception) {
});
$pool->wait();