PHP Classes

HTTP Middleware: Send multiple HTTP requests to remote servers

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 145 All time: 9,143 This week: 524Up
Version License PHP version Categories
http-middleware 1.0Free for non-comm...7HTTP, Web services, PHP 7
Description 

Author

This package can send multiple HTTP requests to remote servers.

It uses the PECL HTTP extension to create a pool of HTTP requests that can be sent in parallel to remote HTTP servers.

The responses are returned in XML or JSON format.

Innovation Award
PHP Programming Innovation award nominee
July 2017
Number 5
Each script of a Web application may require accessing the services of one or more services provided by one or more scripts running on the same or other services.

When it is necessary to execute multiple independent scripts, these can be ran faster if they are executed in parallel.

This package provides a solution that can multiple remote scripts by using the PECL HTTP extension to send the requests and collect the responses.

Manuel Lemos
Picture of Mostafa Abd-El-Hamid
  Performance   Level  
Name: Mostafa Abd-El-Hamid <contact>
Classes: 23 packages by
Country: Egypt Egypt
Age: 40
All time rank: 5595 in Egypt Egypt
Week rank: 214 Up2 in Egypt Egypt Up
Innovation award
Innovation award
Nominee: 5x

Example

<?php

   
namespace REQUEST_EXAMPLE;
   
    use
PECL_MIDDLEWARE_RRQUESTS;
   
    class
ExampleX{
   
        public static function
__init(array $arr, array $postFile, array $putFile, array $postFields,
                array
$options, array $headers, array $put_data, array $query_data,
                array
$body, array $content_type, array $method,
                array
$raw_post_data, array $ssl_options, $clear_history = false) : string{
   
            return (string)\
PECL_MIDDLEWARE_RRQUESTS\RequestsPoolX::__init(
                array
$arr, array $postFile, array $putFile, array $postFields,
                array
$options, array $headers, array $put_data, array $query_data,
                array
$body, array $content_type, array $method,
                array
$raw_post_data, array $ssl_options, $clear_history = false
           
);
           
        }
    }
   
   
   
   
//arr
   
   
$arr = ['url1' => 'http://example.com/url1', 'url2' => 'http://example.com/url2'];
   
   
   
   
//postFile
   
   
$postFile = [];
   
$path_post_file = [
       
0 => 'path/To/image_post_file.png',
       
1 => 'path/To/image2_post_file.png',
       
2 => 'path/To/image3_post_file.png',
    ];
    for(
$i = 0; $i < sizeof($path_post_file); $i++){
       
$type_post_file = pathinfo($path_post_file[$i], PATHINFO_EXTENSION);
       
$data_post_file = file_get_contents($path_post_file[$i]);
       
$base64_encoded_image = 'data:image/' . $type_post_file . ';base64,' . base64_encode($data_post_file);
       
array_push($postFile, $base64_encoded_image);
    }
   
   
   
   
//putFile
   
   
$putFile = [];
   
$path_put_file = [
       
0 => 'path/To/image_put_file.png',
       
1 => 'path/To/image2_put_file.png',
       
2 => 'path/To/image3_put_file.png',
    ];
   
    for(
$i = 0; $i < sizeof($path_put_file); $i++){
       
$type_put_file = pathinfo($path_put_file[$i], PATHINFO_EXTENSION);
       
$data_put_file = file_get_contents($path_put_file[$i]);
       
$base64_encoded_image = 'data:image/' . $type_put_file . ';base64,' . base64_encode($data_put_file);
       
array_push($putFile, $base64_encoded_image);
    }
   
   
   
   
//postFields
   
   
$postFields = [
       
'post_key' => 'post_value',
       
'post_key2' => 'post_value2',
       
'post_key3' => 'post_value3',
    ];
   
   
   
   
//options
   
   
$options = [
       
'option1' => 'value1',
       
'option2' => 'value2',
    ];
   
   
   
   
//headers
   
   
$headers = [
       
'header1' => 'Content-Type: application/xml+rdf',
       
'header2' => 'Content-Type: application/json',
       
'header3' => 'Location: www.example.com',
       
'header4' => 'Authorization: Basic token_no',
       
'header5' => 'Access-Control-Allow-Origin: *',
    ];
   
   
   
   
//put_data
   
   
$put_data = [
       
'key1' => 'value1',
       
'key2' => 'value2',
       
'key3' => 'value3',
    ];
   
   
   
   
//query_data
   
   
$query_data = [
       
'query1' => htmlspecialchars('<?xml version="1.0"?>
                        <note
                        xmlns="'
. $_SERVER['SERVER_NAME'] . '"
                        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                        xsi:schemaLocation="'
. $_SERVER['SERVER_NAME'] . ' src/xsd/select.query.xsd">
                        <request_query_select>
                        <query>
                        <PREFIX foaf: <http://xmlns.com/foaf/0.1/>
                        SELECT ?name
                        WHERE {
                            ?person foaf:name ?name .
                        }
                        </query>
                        </request_query_select>
                        </note>'
, ENT_XML1, 'UTF-8'),
       
'query2' => htmlspecialchars('<?xml version="1.0"?>
                        <note
                        xmlns="'
. $_SERVER['SERVER_NAME'] . '"
                        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                        xsi:schemaLocation="'
. $_SERVER['SERVER_NAME'] . ' src/xsd/select.query.xsd">
                        <request_query_select>
                        <query>
                        PREFIX foaf: <http://xmlns.com/foaf/0.1/>
                        SELECT *
                        WHERE {
                            ?person foaf:name ?name .
                            ?person foaf:mbox ?email .
                        }
                        </query>
                        </request_query_select>
                        </note>'
, ENT_XML1, 'UTF-8'),
       
'query3' => htmlspecialchars('<?xml version="1.0"?>
                        <note
                        xmlns="'
. $_SERVER['SERVER_NAME'] . '"
                        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                        xsi:schemaLocation="'
. $_SERVER['SERVER_NAME'] . ' src/xsd/select.query.xsd">
                        <request_query_select>
                        <query>
                        PREFIX card: <http://www.w3.org/People/Berners-Lee/card#>
                        SELECT ?homepage
                        FROM <http://www.w3.org/People/Berners-Lee/card>
                        WHERE {
                            card:i foaf:knows ?known .
                            ?known foaf:homepage ?homepage .
                        }
                        </query>
                        </request_query_select>
                        </note>'
, ENT_XML1, 'UTF-8'),
       
'query4' => htmlspecialchars('<?xml version="1.0"?>
                        <note
                        xmlns="'
. $_SERVER['SERVER_NAME'] . '"
                        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                        xsi:schemaLocation="'
. $_SERVER['SERVER_NAME'] . ' src/xsd/select.query.xsd">
                        <request_query_select>
                        <query>
                        PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
                        SELECT ?disc ?label
                        {
                          <http://nasa.dataincubator.org/spacecraft/1968-089A> space:discipline ?disc .
                          ?disc rdfs:label ?label
                        }
                        </query>
                        </request_query_select>
                        </note>'
, ENT_XML1, 'UTF-8'),
       
'query5' => htmlspecialchars('<?xml version="1.0"?>
                        <note
                        xmlns="'
. $_SERVER['SERVER_NAME'] . '"
                        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                        xsi:schemaLocation="'
. $_SERVER['SERVER_NAME'] . ' src/xsd/construct.query.xsd">
                        <request_query_construct>
                        <query>
                        PREFIX vCard: <http://www.w3.org/2001/vcard-rdf/3.0#>
                        PREFIX foaf: <http://xmlns.com/foaf/0.1/>
                        CONSTRUCT {
                          ?X vCard:FN ?name .
                          ?X vCard:URL ?url .
                          ?X vCard:TITLE ?title .
                        }
                        FROM <http://www.w3.org/People/Berners-Lee/card>
                        WHERE {
                          OPTIONAL { ?X foaf:name ?name . FILTER isLiteral(?name) . }
                          OPTIONAL { ?X foaf:homepage ?url . FILTER isURI(?url) . }
                          OPTIONAL { ?X foaf:title ?title . FILTER isLiteral(?title) . }
                        }
                        </query>
                        </request_query_construct>
                        </note>'
, ENT_XML1, 'UTF-8'),
       
'query6' => htmlspecialchars('<?xml version="1.0"?>
                        <note
                        xmlns="'
. $_SERVER['SERVER_NAME'] . '"
                        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                        xsi:schemaLocation="'
. $_SERVER['SERVER_NAME'] . ' src/xsd/ask.query.xsd">
                        <request_query_ask>
                        <query>
                        PREFIX prop: <http://dbpedia.org/property/>
                        ASK
                        {
                          <http://dbpedia.org/resource/Amazon_River> prop:length ?amazon .
                          <http://dbpedia.org/resource/Nile> prop:length ?nile .
                          FILTER(?amazon > ?nile) .
                        }
                        </query>
                        </request_query_ask>
                        </note>'
, ENT_XML1, 'UTF-8'),
       
'query7' => htmlspecialchars('<?xml version="1.0"?>
                        <note
                        xmlns="'
. $_SERVER['SERVER_NAME'] . '"
                        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                        xsi:schemaLocation="'
. $_SERVER['SERVER_NAME'] . ' src/xsd/describe.query.xsd">
                        <request_query_describe>
                        <query>
                        PREFIX foaf: <http://xmlns.com/foaf/0.1/>
                        DESCRIBE ?ford WHERE {
                          ?ford foaf:name "FORD MOTOR CO" .
                        }
                        </query>
                        </request_query_describe>
                        </note>'
, ENT_XML1, 'UTF-8'),
       
'query8' => htmlspecialchars('<?xml version="1.0"?>
                        <note
                        xmlns="'
. $_SERVER['SERVER_NAME'] . '"
                        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                        xsi:schemaLocation="'
. $_SERVER['SERVER_NAME'] . ' src/xsd/select.query.xsd">
                        <request_query_select>
                        <query>
                        PREFIX foaf: <http://xmlns.com/foaf/0.1/>
                        SELECT ?name
                        WHERE {
                            <http://www.rdfabout.com/rdf/usgov/congress/committees/SenateArmedServices/StrategicForces>
                                foaf:member ?member .
                            OPTIONAL {
                            <http://www.rdfabout.com/rdf/usgov/congress/committees/SenateArmedServices/Personnel>
                              foaf:member ?member2 .
                              FILTER (?member2 = ?member) .
                            }
                            FILTER (!bound(?member2)) .
                              ?member foaf:name ?name .
                        }
                        </query>
                        </request_query_select>
                        </note>'
, ENT_XML1, 'UTF-8'),
    ];
   
   
   
   
//body
   
   
$body = [
       
'body1' => 'body of message in case working on windows, we add \r\n',
       
'body2' => 'body of message in case working on linux, we add \n',
       
'body3' => 'body of message in case working on mac, we add \r',
    ];
   
   
   
   
//content_type
   
   
$content_type = [
       
'type1' => 'application/xml+rdf',
       
'type2' => 'application/json',
    ];
   
   
   
   
//method
   
   
$method = [
       
'method1' => 'POST',
       
'method2' => 'GET',
    ];
   
   
   
   
//raw_post_data
   
$raw_post_data = [
       
'parameter1' => 'value1',
       
'parameter2' => 'value2',
       
'parameter3' => 'value3',
    ];
   
   
   
   
//ssl_options
   
   
$ssl_options = [
       
'peer_name' => 'destination-host-name.com',
       
'verify_peer' => bool,
       
'verify_peer_name' => bool,
       
'allow_self_signed' => bool,
       
'cafile' => base64_encode($ca_file_content),
       
'capath' => '/path/to/ca/file',
       
'local_cert' => '/path/to/local/cert/file',
       
'local_pk' => '/path/to/local/private/key/file',
       
'passphrase' => 'pass_phrase_of_cert_file',
       
'CN_match' => 'common_name',
       
'verify_depth' => int,
       
'ciphers' => [
                       
'key1' => 'DEFAULT',
                       
'key2' => 'COMPLEMENTOFDEFAULT',
                       
'key3' => 'ALL',
                       
'key4' => 'COMPLEMENTOFALL',
                       
'key5' => 'HIGH',
                       
'key6' => 'MEDIUM',
                       
'key7' => 'LOW',
                       
'key8' => 'eNULL, NULL',
                       
'key9' => 'aNULL',
                       
'key10' => 'kRSA, aRSA, RSA',
                       
'key11' => 'kDHr, kDHd, kDH',
                       
'key12' => 'kDHE, kEDH, DH',
                       
'key13' => 'DHE, EDH',
                       
'key14' => 'ADH',
                       
'key15' => 'kEECDH, kECDHE, ECDH',
                       
'key16' => 'ECDHE, EECDH',
                       
'key17' => 'AECDH',
                       
'key18' => 'aDSS, DSS',
                       
'key19' => 'aDH',
                       
'key20' => 'aECDSA, ECDSA',
                       
'key21' => 'TLSv1.2, TLSv1.0, SSLv3',
                       
'key22' => 'AES128, AES256, AES',
                       
'key23' => 'AESGCM',
                       
'key24' => 'AESCCM, AESCCM8',
                       
'key25' => 'ARIA128, ARIA256, ARIA',
                       
'key26' => 'CAMELLIA128, CAMELLIA256, CAMELLIA',
                       
'key27' => 'CHACHA20',
                       
'key28' => '3DES',
                       
'key29' => 'DES',
                       
'key30' => 'RC4',
                       
'key31' => 'RC2',
                       
'key32' => 'IDEA',
                       
'key33' => 'SEED',
                       
'key34' => 'MD5',
                       
'key35' => 'SHA1, SHA',
                       
'key36' => 'SHA256, SHA384',
                       
'key37' => 'aGOST',
                       
'key38' => 'aGOST01',
                       
'key39' => 'kGOST',
                       
'key40' => 'GOST94',
                       
'key41' => 'GOST89MAC',
                       
'key42' => 'PSK',
                       
'key43' => 'kPSK, kECDHEPSK, kDHEPSK, kRSAPSK',
                       
'key44' => 'aPSK',
                       
'key45' => 'SUITEB128, SUITEB128ONLY, SUITEB192',
                    ],
       
'capture_peer_cert' => bool,
       
'capture_peer_cert_chain' => bool,
       
'SNI_enabled' => bool,
       
'SNI_server_name' => 'host_name.com',
       
'disable_compression' => bool,
       
'peer_fingerprint' => 'md5 || SHA1',
    ];
   
   
   
   
   
//clear_history
   
$clear_history = FALSE;

    print \
REQUEST_EXAMPLE\ExampleX::__init(
       
$arr, $postFile, $putFile, $postFields,
       
$options, $headers, $put_data, $query_data,
       
$body, $content_type, $method,
       
$raw_post_data, $ssl_options, $clear_history
   
);


Details

PECL_HTTP_Middleware

Pecl HTTP Middleware

The XML + RDF + SPARQL + XSD is RequestsPoolX.php

The XSD files are:

reference.xsd
error.xsd

The RESTful is RequestsPool.php


  Files folder image Files (29)  
File Role Description
Files folder imagesrc (2 files, 1 directory)
Files folder imagevendor (1 file, 1 directory)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file composer.lock Data Auxiliary data
Accessible without login Plain text file ExampleX.php Example Class source
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files (29)  /  src  
File Role Description
Files folder imagexsd (14 files)
  Plain text file RequestsPool.php Class Class source
  Plain text file RequestsPoolX.php Class Class source

  Files folder image Files (29)  /  src  /  xsd  
File Role Description
  Accessible without login Plain text file ask.query.xsd Data Auxiliary data
  Accessible without login Image file ask_query_diagram.bmp Icon Icon image
  Accessible without login Plain text file construct.query.xsd Data Auxiliary data
  Accessible without login Image file construct_query_diagram.bmp Icon Icon image
  Accessible without login Plain text file describe.query.xsd Data Auxiliary data
  Accessible without login Image file describe_query_diagram.bmp Icon Icon image
  Accessible without login Plain text file error.xsd Data Auxiliary data
  Accessible without login Image file error_diagram.bmp Icon Icon image
  Accessible without login Plain text file full.query.xsd Data Auxiliary data
  Accessible without login Image file full_query_diagram.bmp Icon Icon image
  Accessible without login Plain text file reference.xsd Data Auxiliary data
  Accessible without login Image file reference_diagram.bmp Data Auxiliary data
  Accessible without login Plain text file select.query.xsd Data Auxiliary data
  Accessible without login Image file select_query_diagram.bmp Icon Icon image

  Files folder image Files (29)  /  vendor  
File Role Description
Files folder imagecomposer (8 files)
  Accessible without login Plain text file autoload.php Aux. Auxiliary script

  Files folder image Files (29)  /  vendor  /  composer  
File Role Description
  Accessible without login Plain text file autoload_classmap.php Aux. Auxiliary script
  Accessible without login Plain text file autoload_namespaces.php Aux. Auxiliary script
  Accessible without login Plain text file autoload_psr4.php Aux. Auxiliary script
  Plain text file autoload_real.php Class Class source
  Plain text file autoload_static.php Class Class source
  Plain text file ClassLoader.php Class Class source
  Accessible without login Plain text file installed.json Data Auxiliary data
  Accessible without login Plain text file LICENSE Lic. License text

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:145
This week:0
All time:9,143
This week:524Up