PHP code example of paulobezerr / soap_threads

1. Go to this page and download the library: Download paulobezerr/soap_threads 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/ */

    

paulobezerr / soap_threads example snippets




$pimple = new Pimple\Container();
$pimple->register(new Soap\Provider);

// Configure and get instance of Pool.
$pimple['soap_pool_threads'] = 2;
$pimple['soap_pool_url'] = 'http://SOAP_URL?wsdl';
$soapPool = $pimple['soap_pool_factory'];

$elements = array(
    array(
        'SOAP_FUNCTION' => 'soap_fuction_name',
        'SOAP_PARAMS' => array('soap', 'function', 'params')
    ),
    array(
        'SOAP_FUNCTION' => 'soap_fuction_name',
        'SOAP_PARAMS' => array('soap', 'function', 'params')
    )
);

foreach ($elements as $item) {
    $soapThreadFunc = $pimple['soap_thread_factory'];
    $soapPool->submit(
        $soapThreadFunc($item['SOAP_FUNCTION'], $item['SOAP_PARAMS'])
    );
}

$workerCount = count($elements);

// Here we collect all soap results and put in array
$soapResults = array();
while ($soapPool->collect(function(Soap\Thread $thread) use (&$soapResults) {
        if ($thread->isGarbage()) {
            $soapResults[] = $thread->soapResult;
        }
        return $thread->isGarbage();
    }) || count($soapResults) < $workerCount) {
    continue;
};

$soapPool->shutdown();

var_dump($soapResults);



use Soap;
use Pool;

$numberOfThreads = 2;
$workerParams = array(
    'http://SOAP_URL?wsdl',
    array('trace' => false, 'exceptions' => false) // Or anything that you need
);

$elements = array(
    array(
        'SOAP_FUNCTION' => 'soap_fuction_name',
        'SOAP_PARAMS' => array('soap', 'function', 'params')
    ),
    array(
        'SOAP_FUNCTION' => 'soap_fuction_name',
        'SOAP_PARAMS' => array('soap', 'function', 'params')
    )
);

$pool = new Pool($numberOfThreads, Worker::class, $workerParams);

foreach ($elements as $item) {
    $pool->submit(new Thread(
        $item['SOAP_FUNCTION'],
        $item['SOAP_PARAMS']
    ));
}

$workerCount = count($elements);

// Here we collect all soap results and put in array
$soapResults = array();
while ($pool->collect(function($thread) use (&$soapResults) {
        if ($thread->isGarbage()) {
            $soapResults[] = $thread->soapResult;
        }
        return $thread->isGarbage();
    }) || count($soapResults) < $workerCount) {
    continue;
};

$pool->shutdown();

var_dump($soapResults);