trigger node js file

后端 未结 2 1104
北恋
北恋 2020-12-17 16:33

I have a JS file that runs via node.js, so normally I crank open a terminal window and type something like node myfile.js and it runs and runs all day; fun.

2条回答
  •  悲&欢浪女
    2020-12-17 16:50

    Assuming you're on Unix-based OS:

    You can run shell commands via the exec() function:

    // in php file
    // to start the script 
    exec("node myscript.js &", $output);
    

    $output becomes an array of each line of output, so you can see what the process id is. Then you would use that process id to kill the script:

    exec("kill " . $processid);
    

提交回复
热议问题