Code Monkey home page Code Monkey logo

php_soap_pthreads's Introduction

SOAP threaded

Average time to resolve an issue Percentage of issues still open

This is a very simple library that facilitates the SOAP threaded requests.
The code can be used as an example of pthread usage or a real implementation of SOAP requests in separated threads.

Requirements

  • PHP7+
  • Pthreads 3.1.6

Examples

With pimple and Pool

<?php

$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);

Without pimple with Pool

<?php

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);

php_soap_pthreads's People

Contributors

pgbezerra avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.