1

Possible Duplicate:
Threads in PHP

Is it possible to make seperate thread to execute something time intensive in PHP? Theres a function that needs to contact an external server but the reply from that server is not important so it would be better to put it in a new thread instead of slowing the whole page load down a few seconds.

Community
  • 1
  • 1
Tom
  • 269
  • 4
  • 14

2 Answers2

1

No, there's no multi-threading in PHP. You can, however use the PCNTL functions to fork a child process.

Narf
  • 14,600
  • 3
  • 37
  • 66
1

This is not php threads per se, however, based on your description, if you're running under *nix, you can handle this quite easily by putting the code you want to run asynchronously in a seperate script and calling it with the exec function using '&' to background the process.

exec('bgscript.php &');
gview
  • 14,876
  • 3
  • 46
  • 51