一键协程化 linux命令

\Swoole\Runtime::enableCoroutine();
go(function(){
    $i = 9999999999999;
    while($i--){
        file_put_contents("./4.7test", $i.PHP_EOL);
    }
    echo 111;
});

go(function(){
    echo 222;
});

协程必须是处理IO的时候(例如fite put),才能起作用

关键代码增加 \Swoole\Runtime::enableCoroutine();

ps -aux |grep mysql  #查看mysql进程id
kill -9 7328
ps -aux |grep mysql  #再次查看确定没有mysql进程
./bin/mysqld_safe --user=root &  #启动


 

或者官方的例子,针对特定的比如CURL

Co::set(['hook_flags' => SWOOLE_HOOK_ALL | SWOOLE_HOOK_CURL]); //真正的协程化所有类型,包括CURL

 SWOOLE_HOOK_CURL

Co::set(['hook_flags' => SWOOLE_HOOK_CURL]);

Co\run(function () {
    $ch = curl_init();  
    curl_setopt($ch, CURLOPT_URL, "http://www.xinhuanet.com/");  
    curl_setopt($ch, CURLOPT_HEADER, false);  
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $result = curl_exec($ch);  
    curl_close($ch);
    var_dump($result);
});



SWOOLE_HOOK_PDO_ODBC

query("select sleep(1) s");
        var_dump($res->fetchAll());
        $dbh = null;
    } catch (PDOException $exception) {
        echo $exception->getMessage();
        exit;
    }
}

Co::set(['trace_flags' => SWOOLE_TRACE_CO_ODBC, 'log_level' => SWOOLE_LOG_DEBUG]);

Co\run(function () {
    test();
});

你可能感兴趣的:(android)