PHP code example of terremoth / php-async

1. Go to this page and download the library: Download terremoth/php-async library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

terremoth / php-async example snippets




erremoth\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 for sending data to the other process
    */
});

// 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();

/*
    Take care with $args if you will use it this way!
    Attackers may explore this to inject commands through RFI/LFI attacks.
    The suggestion is: avoid the users to add/control the $args variable.
*/