Skip to content

terremoth/php-async

Repository files navigation

PHP Async Process

Process functions or files asynchronously without needing AMP, ReactPHP, RxPHP, Fibers, Pthreads, Parallel, Revolt, Pcntl or Swoole.

Just raw PHP! It is magic!

CodeCov Psalm type coverage Psalm level Test Run Status Codacy Badge Code Climate Maintainability License Packagist Downloads

It uses a combination of:

  • serializable-clojure lib
  • Symfony/Process lib
  • and PHP's native Shmop extension

See demos/demo.php for examples.

Installation

composer require terremoth/php-async

Documentation

<?php

require_once 'vendor/autoload.php';

use Terremoth\Async\File;
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 create communications variables between both processes
    */
});

$args = ['--verbose', '-n', '123'];
$asyncFile = new File('existing-php-file.php', $args); // make sure to pass the correct file with its path
$asyncFile->run();

That's it!

About

Async and Parallel* Multitasking with PHP with no threads or reactive libs

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages