homepage Welcome to WebmasterWorld Guest from 54.237.98.229
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
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
adrianTNT

5+ Year Member



 
Msg#: 4254293 posted 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

WebmasterWorld Senior Member



 
Msg#: 4254293 posted 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

5+ Year Member



 
Msg#: 4254293 posted 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

5+ Year Member



 
Msg#: 4254293 posted 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

WebmasterWorld Senior Member



 
Msg#: 4254293 posted 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