1

let say i have send email program which need to run arround 7 hours. but i cant open the browser for 7 hours

beside cronjob,

ignore_user_abort() will it be a solution?

will the script stop when all email has sent and the program has finish the loop?

or it will keep eating the server memory?

some people said u may need to add some output at the end of the program to avoid the program run forever?

and some people also said echo a litte bit string will not stop the script, but has to use ob_flush, any example for this?

user192344
  • 1,274
  • 6
  • 22
  • 36

2 Answers2

0

You don't want a single seven hour running PHP process on your machine. It will likely leak memory all over the place. Break the eMail-sending into chunks and send them asynchronously and/or have a look at http://gearman.org/

Also, ignore_user_abort does only apply to PHP CLI.

Gordon
  • 312,688
  • 75
  • 539
  • 559
  • actually, i send 10 email per thead and sleep 30 second, that's y to run 7 hours if the client want to send 10000 email. anyway for gearman, will it be a solution for mu-til process? – user192344 Feb 03 '10 at 02:15
  • @unknown Both approaches use separate processes to send the eMails. Like I said, you want to do it asynchronously. When the script is triggered, it will fork the mail sending processes only and then end, while the mail sending processes run on their own. – Gordon Feb 03 '10 at 08:00
  • `ignore_user_abort` is not just for CLI. When set to true, it means that PHP should complete the request even if the connection to the client is terminated. – gnud Feb 04 '10 at 14:43
  • ignore_user_abort works whenever a php script is running, Gordon. http://www.php.net/manual/en/function.ignore-user-abort.php – Horia Dragomir Feb 04 '10 at 14:44
  • Ok, guess I misunderstood the *When running PHP as a command line script* in the manual then. Thanks for pointing it out. – Gordon Feb 04 '10 at 15:02
  • Hmm by me it didn't work by browser called scripts. Browser timeout stopped my scripts :S I'll try it out tomorrow with scripts called by cron. – inf3rno Feb 09 '11 at 18:12
0

After the loop, you script will exit whether ignore_user_abort is set to true or not.

If you carefully design the script, you should not have any problems with memory leakage.

Horia Dragomir
  • 2,858
  • 24
  • 21