PHP Classes
elePHPant
Icontem

async: Run code asynchronously using the PHP program

Recommend this page to a friend!
  Info   View files Example   View files View files (7)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2018-01-04 (1 month ago) RSS 2.0 feedNot yet rated by the usersTotal: Not yet counted Not yet ranked
Version License PHP version Categories
async 1.0MIT/X Consortium ...5PHP 5, Language
Description Author

This class can run code asynchronously using the PHP program.

It can take the code of a given closure and makes it run using the PHP program to create a separate process.

The class can take callback functions to run when the called code finishes, or in case of error.

  Performance   Level  
Name: Kacper Rowinski <contact>
Classes: 8 packages by
Country: Poland Poland
Innovation award
Innovation award
Nominee: 3x

Details

How this work?

Well its basically "exec" with serialised closure. "Dressed" in nice libs like symfony process and console. I serialise callable function and sent to child process by exec. To get callback I register shutdown function and wait for process to finish.

Why not pcntl ?

  • Pcntl extension fork, so you can forget using it in web applications like apache2/php-fpm etc its only for CLI
  • forks retains the parent state (for example open files) so its problematic

Problems ?

  • Calling exec is slower then fork
  • Some resource/function/data must be passed directly to closure

Some research

  • https://www.phproundtable.com/episode/asynchronous-php - good start to "know how" make php async
  • https://amphp.org/ - non-blocking framework for PHP

Example ?

Sure take a look - https://github.com/krowinski/async/blob/master/example/example.php

Supports M$ Windows?

NO.

TODO

  • process limit
  • timeouts
  • tests
  Files folder image Files  
File Role Description
Files folder imagebin (1 file)
Files folder imageexample (1 file)
Files folder imagesrc (1 directory)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  bin  
File Role Description
  Accessible without login Plain text file console Example Example script

  Files folder image Files  /  example  
File Role Description
  Accessible without login Plain text file example.php Example Example script

  Files folder image Files  /  src  
File Role Description
Files folder imageAsync (3 files)

  Files folder image Files  /  src  /  Async  
File Role Description
  Plain text file AsyncCall.php Class Class source
  Plain text file AsyncChildCommand.php Class Class source
  Plain text file AsyncChildResponse.php Class Class source

 Version Control Unique User Downloads  
 100%
Total:0
This week:0