<commit_before><?php
$redirect_stdout = false;
$workers = [];
$worker_num = 1;

//swoole_process::daemon(0, 1);

for($i = 0; $i < $worker_num; $i++)
{
    $process = new swoole_process('callback_function_async', $redirect_stdout);
    $pid = $process->start();
    $workers[$pid] = $process;
    //echo "Master: new worker, PID=".$pid."\n";
}

function callback_function(swoole_process $worker)
{
    //echo "Worker: start. PID=".$worker->pid."\n";
    //recv data from master
    $recv = $worker->read();

    echo "From Master: $recv\n";

    //send data to master
    $worker->write("hello master\n");

    sleep(2);
    $worker->exit(0);
}

function callback_function_async(swoole_process $worker)
{
    //echo "Worker: start. PID=".$worker->pid."\n";
    //recv data from master
    $GLOBALS['worker'] = $worker;
   
    swoole_async_signal(15, function($signal_num){
		echo "signal call = $signal_num\n";
    });

    swoole_event_add($worker->pipe, function($pipe) {
        $worker = $GLOBALS['worker'];
        $recv = $worker->read();

        echo "From Master: $recv\n";

        //send data to master
        $worker->write("hello master\n");

        //sleep(2);

        //$worker->exit(0);
    });
}

foreach($workers as $pid => $process)
{
    $process->write("hello worker[$pid]\n");
    echo "From Worker: ".$process->read();
}

for($i = 0; $i < $worker_num; $i++)
{
    $ret = swoole_process::wait();
    $pid = $ret['pid'];
    unset($workers[$pid]);
    echo "Worker Exit, PID=".$pid.PHP_EOL;
}

sleep(10000);<commit_msg>Update swoole_process example<commit_after><?php
$redirect_stdout = false;
$workers = [];
$worker_num = 1;

//swoole_process::daemon(0, 1);
for($i = 0; $i < $worker_num; $i++)
{
    $process = new swoole_process('child_async', $redirect_stdout);
    $pid = $process->start();
    $workers[$pid] = $process;
    //echo "Master: new worker, PID=".$pid."\n";
}

master_async($workers);
//master_sync($workers);

//异步主进程
function master_async($workers)
{
    swoole_process::signal(SIGCHLD, function ($signo) use ($workers) {
        $ret = swoole_process::wait();
        $pid = $ret['pid'];
        unset($workers[$pid]);
        echo "Worker Exit, PID=" . $pid . PHP_EOL;
    });

    /**
     * @var $process swoole_process
     */
    foreach($workers as $pid => $process)
    {
        swoole_event_add($process->pipe, function($pipe) use ($process) {
            $recv = $process->read();
            if ($recv) echo "From Worker: " . $recv;
        });
        $process->write("hello worker[$pid]\n");
    }
}

//同步主进程
function master_sync($workers)
{
    foreach($workers as $pid => $process)
    {
        $process->write("hello worker[$pid]\n");
        echo "From Worker: ".$process->read();
    }
}

function child_sync(swoole_process $worker)
{
    //echo "Worker: start. PID=".$worker->pid."\n";
    //recv data from master
    $recv = $worker->read();

    echo "From Master: $recv\n";

    //send data to master
    $worker->write("hello master\n");

    sleep(2);
    $worker->exit(0);
}

function child_async(swoole_process $worker)
{
    //echo "Worker: start. PID=".$worker->pid."\n";
    //recv data from master
    $GLOBALS['worker'] = $worker;

    swoole_process::signal(SIGTERM, function($signal_num) use ($worker) {
		echo "signal call = $signal_num, #{$worker->pid}\n";
    });

    swoole_event_add($worker->pipe, function($pipe) use($worker) {
        $recv = $worker->read();
        echo "From Master: $recv\n";
        $worker->write("hello master\n");
    });
}
{'fraction_non_alphanumeric': 0.19920769666100735, 'fraction_numerical': 0.00622524052065648, 'mean_word_length': 3.0353881278538815, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7528359', 'n_tokens_mistral': 1248, 'n_tokens_neox': 1230, 'n_words': 253}