terremoth / php-async
Write async PHP processes or process async files with no phtreads, parallel or reactive libs
v1.0.5
2024-12-11 11:53 UTC
Requires
- php: ^8.2
- ext-fileinfo: *
- ext-shmop: *
- ext-zlib: *
- laravel/serializable-closure: ^2.0
- symfony/process: ^7.2
Requires (Dev)
- nikic/php-parser: ^4.10
- phpmd/phpmd: @stable
- phpunit/phpunit: ^10.0
- squizlabs/php_codesniffer: *
- vimeo/psalm: ^5.0
README
Process functions or files asynchronously without needing AMP, ReactPHP, RxPHP, Fibers, Pthreads, Parallel, Revolt, Pcntl or Swoole.
Just raw PHP! It is magic!
It uses a combination of:
- serializable-clojure lib
- Symfony/Process lib
- and PHP's native Shmop extension
Warning
it does not works on MSYS or MINGW terminals! However, It will work fine on both Windows (cmd and powershell) and Linux.
See demos/demo.php for examples.
Installation
composer require terremoth/php-async
Documentation
<?php require_once 'vendor/autoload.php'; use Terremoth\Async\PhpFile; use Terremoth\Async\Process; $process = new Process(); $process->send(function () { /* // anything you want to process here // Important note: do not use closure vars, like: // $process->send(function () use ($var1, $var2, ...) { ... }); // since the closure will be processed in another file. // Write everything you want without outside dependencies here // In a future version I will create communications variables between both processes */ }); // Another way to use is if you want to just process a file Asynchronously, you can do this: $args = ['--verbose', '-n', '123']; $asyncFile = new PhpFile('existing-php-file.php', $args); // make sure to pass the correct file with its path $asyncFile->run();
That's it!