workerman在WINDOWS下用命令行啟動,有點不方便。想改成WINDOWS服務(wù)程序方式運行.
想法如下:
1,下載PHP的擴(kuò)展:php_win32service.dll
2,在Select.php中修改:
public function loop()
{
$e = null;
while (1)
{
....
}
}
改成:
public function loop()
{
$e = null;
while (1) {
if (WIN32_SERVICE_CONTROL_STOP == win32_get_last_control_message()) {
die("服務(wù)已停止!");
}
}
}
不知道可行不?如果可行對性能有影響沒?
查看PHP官方文檔:
//檢測服務(wù)是否存在
if (!win32_start_service_ctrl_dispatcher( _SERVICENAME )) {
die("沒有發(fā)現(xiàn)正在運行的 服務(wù)");
}
win32_set_service_status(WIN32_SERVICE_RUNNING);
//如果運行中
while (WIN32_SERVICE_CONTROL_STOP != win32_get_last_control_message())
{
# do your work here.
# try not to take up more than 30 seconds before going around the loop
# again
}
知道這個while要寫到哪里去!Select.php文件在的loop中修改通不過!
版主幫幫寫下!
官方的例子:
<?php
class TestClass {
private $args;
function __construct($arg) {
$this->args = $arg;
$this->run();
}
private function run() {
if ($this->args == 'run') {
win32_start_service_ctrl_dispatcher('test_service');
while (WIN32_SERVICE_CONTROL_STOP != win32_get_last_control_message()) {
# do your work here.
# try not to take up more than 30 seconds before going around the loop
# again
}
}
}
}
$object = new TestClass($argv);
?>
問題決解了!
寫了個空殼的服務(wù)程序,在里面直接執(zhí)行php.exe start.php
停止服務(wù)時!KILL掉PHP.EXE的進(jìn)程。
已穩(wěn)定運行兩周了。
再為不為在WINDOWS平臺下要登陸系統(tǒng)在命令行運行的煩惱!
[attach]172[/attach]