PHP Classes

PHP Asynchronous HTTP Request: Queue and send multiple asynchronous HTTP requests

Recommend this page to a friend!
  Info   View files Example   View files View files (22)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 94 This week: 1All time: 9,860 This week: 560Up
Version License PHP version Categories
req-async 1.0.0MIT/X Consortium ...5HTTP, PHP 5
Description 

Author

This package can queue and send multiple asynchronous HTTP requests.

It can store in an array the parameters of HTTP requests to be sent to remote Web servers.

The parameters define details of the HTTP requests like the URL, HTTP method, the request headers, file to store cookies, etc..

The package can send the HTTP requests in parallel using the Curl extension and returns the results when all requests are finished.

Picture of Mateo
  Performance   Level  
Name: Mateo <contact>
Classes: 21 packages by
Country: Peru Peru
Age: ???
All time rank: 21074 in Peru Peru
Week rank: 8 Up1 in Peru Peru Up
Innovation award
Innovation award
Nominee: 9x

Winner: 3x

Example

<?php

require './vendor/autoload.php';
use
Async\Req;
use
Async\Run;

$req = new Req();
$promise = array();


$promise[] = $req::Get('https://httpbin.org/get'); // GET method
$promise[] = $req::Post('https://httpbin.org/post'); // POST method
$promise[] = $req::Put('https://httpbin.org/put'); // CUSTOM method


$headers = ['Origin: https://google.com/', 'X-msg: Testing async resquest'];
$post = ['name' => 'John', 'age' => '25'];

// Using customs headers
$promise[] = $req::Get('https://httpbin.org/get', $headers);

// Using custom post data
$promise[] = $req::Post('https://httpbin.org/post', $post);

// Using custom headers and post data
$promise[] = $req::Post('https:/httpbin.org/post', $post, $headers);

// Using cookies | GET method
$promise[] = $req::Get('https://httpbin.org/cookies/set?name=John&age=25', null, null, 'file_example_cookie_file');
$promise[] = $req::Get('https://httpbin.org/cookies', $headers, ['METHOD' => 'TUNNEL', 'SERVER' => '103.28.149.107:3128'], 'file_example_cookie_file'); // Headers and http proxy
$promise[] = $req::Get('https://httpbin.org/get', $headers, ['METHOD' => 'TUNNEL', 'SERVER' => '', 'AUTH' => 'user:pass'], 'file_example_cookie_file'); // Headers and auth proxy


print_r(Run::Async($promise));
// echo json_encode(Run::Async($promise));


Details

Async requests

Create new request

$req = new Req();
$promise = array();
$promise[] = $req::Get('https://httpbin.org/get'); // GET method
$promise[] = $req::Post('https://httpbin.org/post'); // POST method
$promise[] = $req::Put('https://httpbin.org/put'); // CUSTOM method

Run all request

$response = Run::Async($promise);

Proxy sintax

# PROXY (http/s, socks4, socks5)
$server = [
    "METHOD" => "TUNNEL",
    "SERVER" => "ip:port"
];

# Windscribe
$server = [
    "METHOD" => "CUSTOM",
    "SERVER" = "socks5h://socks-us.windscribe.com:1080",
    "AUTH" => "w07l3gbt-r6vxdfpb:ucxqefrada3h"
];

# Webshare
$server = [
    "METHOD" => "CUSTOM",
    "SERVER" = "p.webshare.io:80",
    "AUTH" => "user-rotate:pass"
];


# APIFY valid syntax example
$server = [
    "METHOD" => "CUSTOM",
    "SERVER" = "http://proxy.apify.com:8000",
    "AUTH" => "auto:pasword"
];

# IPVANISH valid syntax example
$server = [
    "METHOD" => "CUSTOM",
    "SERVER" => "akl-c12.ipvanish.com:1080",
    "AUTH"   => "my_zone_customer_id:my_zone_customer_password"
];

Get sintax

$headers = ['Origin: https://google.com/', 'MSG: testing'];
$server = ["METHOD" => "TUNNEL", "SERVER" => "ip:port"];

$req = new Req();
$promise = array();

$promise[] = $req::Get('https://httpbin.org/get');
$promise[] = $req::Get('https://httpbin.org/get', $headers); // Using headers
$promise[] = $req::Get('https://httpbin.org/cookies/set?name=John&age=25', $headers, null, 'file_example_cookie_file'); // Using headers and cookies
$promise[] = $req::Get('https://httpbin.org/get', null, $server); // Using only proxy

$response = Run::Async($promise); // Run all resquests

Post sintax

$headers = ['Origin: https://google.com/', 'MSG: testing'];
$server = ["METHOD" => "TUNNEL", "SERVER" => "ip:port"];
$post = ['name' => 'Jhon', 'age' => 25];

$req = new Req();
$promise = array();

$promise[] = $req::Post('https://httpbin.org/post'); // Simple resquest
$promise[] = $req::Post('https://httpbin.org/post', http_build_query($post)); // Post data
$promise[] = $req::Post('https://httpbin.org/post', $post); // Post (in json)
$promise[] = $req::Post('https://httpbin.org/post', $post, $headers); // Post (in json) and headers
$promise[] = $req::Post('https://httpbin.org/cookies/set?name=John&age=25', null, $headers, null, 'cookie_example'); // Using headers and cookies

Custom methods

$req = new Req();
$promise = array();

/
 * Format:
 * $promise[] = $req::MethodName('url', $post_data, $headers, $server, $cookie_name);
 * $response = Run::Async($promise);
*/
$promise[] = $req::Put('https://httpbin.org/put');
$promise[] = $req::Patch('https://httpbin.org/patch');
$promise[] = $req::Delete('https://httpbin.org/delete');

Run requests

$req = new Req();
$promise = array();

for ($i=0; $i < 10; $i++) {
    $promise[] = $req::Get('https://httpbin.org/get');
}

$response = Run::Async($promise); // Run all resquests
$response = Run::Async([$promise[0], $promise[1]]); // Run someone resquests
$response = Run::Async($promise, 100); // Modified ms

Installation

Install source from GitHub

To install the source code:

$ git clone https://github.com/Mateodioev/req-async.git

Install from Composer

$ composer require mateodioev/async-curl-requests:dev-master

And include it in your scripts:

require './vendor/autoload.php';
use Async\Req;
use Async\Run;

  Files folder image Files  
File Role Description
Files folder imagesrc (6 files)
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 examples.php Example Example script
Accessible without login Plain text file readme.MD Doc. Documentation

  Files folder image Files  /  src  
File Role Description
  Plain text file Cookie.php Class Class source
  Plain text file Headers.php Class Class source
  Plain text file Proxy.php Class Class source
  Plain text file Req.php Class Class source
  Plain text file Run.php Class Class source
  Plain text file StringUtil.php Class Class source

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

  Files folder image Files  /  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 installed.php Aux. Auxiliary script
  Plain text file InstalledVersions.php Class Class source
  Accessible without login Plain text file LICENSE Lic. License text
  Accessible without login Plain text file platform_check.php Aux. Auxiliary script

 Version Control Unique User Downloads Download Rankings  
 100%
Total:94
This week:1
All time:9,860
This week:560Up