PHP Classes

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 (1)   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 192 All time: 8,521 This week: 200Up
Version License PHP version Categories
async 1.0MIT/X Consortium ...5PHP 5, Language
Description 

Author

Kacper Rowi?ski


Contributor

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.

Picture of Kacper Rowinski
  Performance   Level  
Name: Kacper Rowinski <contact>
Classes: 14 packages by
Country: Poland Poland
Age: 39
All time rank: 92726 in Poland Poland
Week rank: 79 Up2 in Poland Poland Up
Innovation award
Innovation award
Nominee: 8x

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 Download Rankings  
 100%
Total:192
This week:0
All time:8,521
This week:200Up