| Triggering php scripts in background by curl, exec, cron jobs |
adrianTNT

msg:4254295 | 6:28 pm on Jan 17, 2011 (gmt 0) | I need to trigger a php script to run every 1-2 seconds (an email sender). Because including it in my page footer would cause some delay visible to users, I want to trigger it in background, I was thinking to trigger an EXEC from page footer by PHP like this: <?php exec("curl http://example.com/script.php"); ?> but is the same because curl waits for the script to run, maybe curl has an option that just triggers this without waiting for the output?
|
Readie

msg:4254299 | 6:39 pm on Jan 17, 2011 (gmt 0) | You could include it in your footer:
<?php
require_once 'footer.php'; ob_flush(); require_once 'email_script.php';
?> Would have no noticable delay to the end user.
|
adrianTNT

msg:4254305 | 6:52 pm on Jan 17, 2011 (gmt 0) | I didn't knew that, so the ob_flush() will finish the output that is sent to user and continue the rest in background?
|
adrianTNT

msg:4254320 | 7:14 pm on Jan 17, 2011 (gmt 0) | I made a quick test like this: echo "test"; ob_flush(); sleep(5); If the of_flush does what I thought, I would expect it to load page instantly but it does wait the 5 seconds before showing the text.
|
Readie

msg:4254595 | 12:49 pm on Jan 18, 2011 (gmt 0) | Hmm. That's a bit odd. Try witbh just flush() rather than ob_flush() then. Or, it could just be sleep() alters behaviour and is not an accurate representation of a slow script running.
|
|
|