可自动结束的程序

最后更新于:2022-04-02 02:18:54

[TOC] ## demo index.php ``` function isWindow(){ return substr(php_uname(), 0, 7) == "Windows"; } function execInBackground($cmd) { if (isWindow()){ pclose(popen("start /B ". $cmd, "r")); } else { exec($cmd . " > /dev/null &"); } } $cmd = "/usr/bin/php client.php"; // or php client.php execInBackground($cmd); ?>

success

``` client.php ``` $redis = new Redis(); if ( ! $redis->connect('127.0.0.1', 6379)) { print_r($redis->getLastError()); } $i=0; while (true){ if ($i==10){ return true; } $i++; //code //$redis->publish("chat", $i); //redis 发布 ,用 SUBSCRIBE chat 接受 sleep(1); } ``` 执行 ``` curl http://127.0.0.1:8080/index.php ```
';