I want a long looped script to work in the background! ???

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
alexeiz
Forum Newbie
Posts: 12
Joined: Mon Oct 20, 2003 9:31 pm
Location: Los Angeles

I want a long looped script to work in the background! ???

Post by alexeiz »

Here is a brieef description

I have a function send_ad(...) that submits an ad to remote form page using cURL functions - works well.

Finction send ad(..) is called from a loop inside other function send_to_all(...)
which goes through many (20-200) of these form pages.

This also works well. The only thing - it takes time and makes the browser busy waiting for the results. I want the browser to disconnect and be free for other use immediately after the user clicks on "Proceed" button that starts submission process.

Here is what I tried:

if ($action == 'proceed') {
echo "<p>Submission started, you can leave this page now!</P>";
for($j = 0; $j < 300; $j++) {
echo ' ';
}
flush();
ob_flush();
send_to_all($user,$mess_id,$today);
exit;
}

I wanted the page to display the message " Submission started..." right after the user vlicks on proceed and the script in send-to_all() function to proceeed.

Instead the browser is waiting for send_to_all() function to complet and onlt THEN displayes the message. It looks like neither flush() nor ob_flash don't work.

If I quit the browser, the function continues to work until completion.

What is wrong??
jollyjumper
Forum Contributor
Posts: 107
Joined: Sat Jan 25, 2003 11:03 am

Post by jollyjumper »

Hi Alexiz,

I think the exec function is what you need. You can find more information about this function on http://www.php.net

Greetz Jolly.
User avatar
dull1554
Forum Regular
Posts: 680
Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W

Post by dull1554 »

or u could simply set up a cron to do the job...
alexeiz
Forum Newbie
Posts: 12
Joined: Mon Oct 20, 2003 9:31 pm
Location: Los Angeles

Post by alexeiz »

Thanks!

I really need to read more on the subject. I even don't understand what could be the "program" that is to be a parameter for exec() function. Could it be just a file with PHP script?

My original script files eache result in MySQL table for later viewing - is it OK?

Obviously I just don't have enough knowlege on all that!

I don't think I can use cron - I have to pass the parameters to the function that are generated by each user.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

alexeiz wrote: I really need to read more on the subject. I even don't understand what could be the "program" that is to be a parameter for exec() function. Could it be just a file with PHP script?
It could be the command to invoke the CLI version of the php with script name passed as the parameter:

Code: Select all

exec("/usr/local/bin/php -q /path/to/your/script.php 2>&1 >/dev/null");
Post Reply