0

Possible Duplicate:
php execute a background process

I need to get some info from the user, send them some text back and process the data in the background, so after sending the text connectionwith browser should be closed and then the data processed.

How to achieve that?

Community
  • 1
  • 1
419
  • 179
  • 1
  • 3
  • 10
  • @ajreal - This is not necessarily a duplicate. If he wants the process to execute after the execution of the original PHP script, the solution in the question you think is a duplicate will not work. – Francois Deschenes Jun 30 '11 at 05:39
  • as long both are triggering a php process, i don't really see the differences – ajreal Jun 30 '11 at 05:51
  • @ajreal - While `exec` can be used to trigger background processes, the output must be redirected for it to continue without interfering with the page. When it's in the background, it could hang or take a long time to execute. If many of those are started simultaneously, it could take the server down. In my opinion, a better alternative is a daemon. – Francois Deschenes Jun 30 '11 at 06:10

2 Answers2

2

You'll most likely want to save the information to a database and write some sort of daemon that processes the information offline. The PEAR System_Daemon would be a great starting point.

Some sections of their documentation you might be interested in:

  1. What is Daemon
  2. Daemons vs Cronjobs
  3. Installation
  4. Example
Francois Deschenes
  • 24,816
  • 4
  • 64
  • 61
0

You may get use of pcntl_fork. See the manual example.

Igor
  • 2,619
  • 6
  • 24
  • 36
  • Processes forked with `pcntl_fork` die when the parent process ends. This would require for the browser to continue loading until the child process is done which is not what he's looking for, at least I don't think. – Francois Deschenes Jun 30 '11 at 05:41