ansbar Posted December 16, 2007 Share Posted December 16, 2007 Hi! I have a script which will be sending, lets say, 10 mails a time. This takes like 25secs. I dont want the user to have to wait for the script to finish, instead I want the script to run as a background process or something. (My webhotel which doesn't allow cron jobs or exec()s.) This is what I have accomplished: From a php page I run <img src="myscript.php"> myscript.php concists of : -------------- $sFileUrl = 'gfx/spacer.gif' ; header('Content-Type: image/gif'); readfile($sFileUrl) ; the mailcode is below.. -------------- This creates the process, so even if I close the browser it still finishes the mail job. However the browser continues to show the "loading page" icon if I dont close the browser. So my question is: Is there a way to make the browser think that the page is done loading so the script is loading in the background (like now) but the browser looks like it is done? I would be extremely grateful if some genius could have a look. Thanks! //Per Quote Link to comment Share on other sites More sharing options...
revraz Posted December 16, 2007 Share Posted December 16, 2007 What does your mail() statement look like, are you processing a result? You can try to omit the result if you are to see if it speeds it up. Quote Link to comment Share on other sites More sharing options...
ansbar Posted December 17, 2007 Author Share Posted December 17, 2007 The mailcode below. There is no result involved, I guess? =) I read somewhere that you could fool the browser to think it was done by sending different headers like 200 OK and the file size but I can't get that to work... I've also tride using ob_flush and simular with no result. ----------------------------- $connection = mysql_connect("$server","$user","$password") or die ("Could not connect to DB server."); $resultMailList = mysql_db_query($database,"select * from ma_mail where ma_status = '1'"); while($row = mysql_fetch_array($resultMailList)){ $toMail = $row[ma_mail]; $fromMail = "somemail@mail.se"; $message = "Hej " .$row['ma_message']. "\nblablabalal"; if(mail($toMail, "texttext", $message,"From:".$fromMail."\nReturn-Path:".$fromMail,"-f".$fromMail."")) { mysql statement }else{ break; } } Quote Link to comment Share on other sites More sharing options...
trq Posted December 17, 2007 Share Posted December 17, 2007 The easiest way is to run your script as a cli (command line interpreter) script. As an example, try this. index.php <?php echo "Before foo<br />"; exec("foo.php &"); // the & puts the process in the background. echo "After foo"; ?> foo.php #!/usr/bin/php <?php sleep(20); ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.