Page 1 of 1

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

Posted: Sat Mar 20, 2004 12:40 pm
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??

Posted: Sat Mar 20, 2004 2:14 pm
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.

Posted: Sat Mar 20, 2004 3:02 pm
by dull1554
or u could simply set up a cron to do the job...

Posted: Sat Mar 20, 2004 3:15 pm
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.

Posted: Sat Mar 20, 2004 3:59 pm
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");