Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
931 views
in Technique[技术] by (71.8m points)

multithreading - most simple way to start a new process/thread in PHP

Scenario:

  1. Shared hosting, so no ability to install new extensions + no CRON
  2. A submitted request needs to perform some heavy processes.
  3. I want the answer to the client to go as fast as possible, and the heavy lifting to continue immediately, but not stop the client.
  4. can be on a new thread (if it is possible) also no problem with starting a new process.

What is the best way to do this?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

On *nix:

exec('/path/to/executable > /dev/null 2>&1 &');

On Windows:

$WshShell = new COM('WScript.Shell'); 
$oExec = $WshShell->Run('C:pathoexecutable.exe', 0, false);

Both of these will spawn a new process that will run a-synchronously, completely disconnected from the parent. As long as your host allows you to do it.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...