PHP code example of sidorkinalex / multiphp

1. Go to this page and download the library: Download sidorkinalex/multiphp 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/ */

    

sidorkinalex / multiphp example snippets





$key=$argv[1]; //
SidorkinAlex\Multiphp\Thread::shell_start($key);


  $paramsFromThread = 3;
        $test = new CThread($paramsFromThread,function ($n){
            for ($i = 0; $i<$n; $i++){
                $pid=getmypid();
                file_put_contents('test1.log', $i." my pid is {$pid} \n", FILE_APPEND);
                sleep(3);
            }
            return 'test1';
        });
        $test->start();

        $test2 = new CThread($paramsFromThread,function ($n){
            for ($i = 0; $i<$n; $i++){
                $pid=getmypid();
                file_put_contents('test2.log', $i." my pid is {$pid} \n", FILE_APPEND);
                sleep(3);
            }
            return 'test2';
        });
        $test2->start();
        $result1 = $test->getCyclicalResult();
        $result2 = $test2->getCyclicalResult();

  


$key=$argv[1]; //
SidorkinAlex\Multiphp\Thread::shell_start($key);


  $paramsFromThread = 3;
        $test = new CThread($paramsFromThread,function ($n){
            for ($i = 0; $i<$n; $i++){
                $pid=getmypid();
                file_put_contents('test1.log', $i." my pid is {$pid} \n", FILE_APPEND);
                sleep(3);
            }
            return 'test1';
        });
        $test->start();

        $test2 = new CThread($paramsFromThread,function ($n){
            for ($i = 0; $i<$n; $i++){
                $pid=getmypid();
                file_put_contents('test2.log', $i." my pid is {$pid} \n", FILE_APPEND);
                sleep(3);
            }
            return 'test2';
        });
        $test2->start();
        $result1 = $test->getCyclicalResult();
        $result2 = $test2->getCyclicalResult();