homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

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

 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:

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?



 6:39 pm on Jan 17, 2011 (gmt 0)

You could include it in your footer:


require_once 'footer.php';
require_once 'email_script.php';


Would have no noticable delay to the end user.


 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?


 7:14 pm on Jan 17, 2011 (gmt 0)

I made a quick test like this:

echo "test";

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.


 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.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved