PHP Classes

File: README.md

Recommend this page to a friend!
  Classes of Lucas Marques Dutra   PHP Async   README.md   Download  
File: README.md
Role: Documentation
Content type: text/markdown
Description: Read me
Class: PHP Async
Run scripts in parallel using the PHP CLI command
Author: By
Last change:
Date: 18 days ago
Size: 2,677 bytes
 

Contents

Class file image Download

PHP Async Process

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

Just raw PHP! It is magic!

<!-- codecov Test Coverage --> Psalm type coverage Psalm level Test Run Status Codacy Badge Maintainability License Packagist Downloads

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();
$age = 30;
$name = 'John Doe';
$fruits = ['orange', 'apple', 'grape'];

$process->send(function () use ($age, $name, $fruits) {
    /*
    // Anything you want to process here, you can use closure vars
    // 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!