PHP code example of sanket3dx / phpgo

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

    

sanket3dx / phpgo example snippets



$ch = phpgo\channel();

phpgo\go(function() use ($ch) {
    echo "Sending from goroutine...\n";
    phpgo\send($ch, "Hello form Go!");
});

$msg = phpgo\receive($ch);
echo "Received: $msg\n";


$ch1 = phpgo\channel();
$ch2 = phpgo\channel();

// ... spawn producers ...

$result = phpgo\select([
    phpgo\case_recv($ch1),
    phpgo\case_recv($ch2),
    phpgo\case_default(fn() => "Timeout")
]);

var_dump($result['value']);
bash
   php -d extension=`pwd`/modules/phpgo.so script.php