Hello Steve, Btw, the built-in mail() function is tooooo slow to send such amount of mail. Consider using SMTP (if you don't). -- With best regards from Ukraine, Andre Skype: Francophile Twitter: http://twitter.com/m_elensule Facebook: http://facebook.com/menelion ----- Original message ----- From: Steve Staples <sstaples@xxxxxxxx> To: php-general@xxxxxxxxxxxxx <php-general@xxxxxxxxxxxxx> Date: Monday, December 6, 2010, 6:41:34 PM Subject: Redirect output to a file on the web server On Mon, 2010-12-06 at 16:19 +0000, Richard Quadling wrote: > On 6 December 2010 15:46, Ferdi <ferdinand.s@xxxxxxxxx> wrote: > > On 6 December 2010 20:47, Steve Staples <sstaples@xxxxxxxx> wrote: > > > >> On Mon, 2010-12-06 at 20:29 +0530, Ferdi wrote: > >> > Greetings List members, > >> > > >> > I have a script that takes quite a while to run, one or two hours, I wish > >> to > >> > redirect the normal php output to a file on the webserver itself. I don't > >> > mind if in the process, the browser displays a blank page. The reason I > >> want > >> > to do this is that if the script crashes or the browser Is closed by > >> > mistake, I have absolutely no record of where the script stopped running. > >> > > >> > I could use code like below > >> > At the beginning of the script: > >> > ob_start(); > >> > > >> > At the end of the script: > >> > $page = ob_get_contents(); > >> > ob_end_flush(); > >> > $fp = fopen("output.html","w"); > >> > fwrite($fp,$page); > >> > fclose($fp); > >> > > >> > However, I see some problems with this: > >> > I'm not too sure of the size of the output. It may balloon to over the > >> > buffering limit (in PHP? Apache?) and then what happens? > >> > Secondly, if the script crashes before the end, I won't get any output. > >> > Finally, I am using a library in the script that outputs status and error > >> > messages of its own. So, if I manually opened a file and used fwrite() > >> > alongside echo for my messages, I would lose out on those messages. > >> > > >> > Anybody has any pointers on how you could send the output not only to a > >> > browser, but also to a file on the webserver? If not, at least to a file? > >> > > >> > Thanks and regards, > >> > Ferdi > >> > >> Just curious, but if it takes that long to run, why are you running it > >> from a browser? why not run it from the commandline, that way you dont > >> have to change your php.ini for the webserver (increasing the timeout, > >> memory limits, etc etc... you can change those for the CLI only? > >> > >> 2 hours is a long time to "hope" that the browser doesn't close, or > >> connectivity doesn't get interupted for even 1 microsecond... > >> > >> if the script has "breaks" in it, where it starts to do something else, > >> you can put in an email to yourself, to say "hey, we're HERE now" > >> > >> but i would look into running it from the CLI over the webserver, you > >> would be less likely to run into issues on something that takes that > >> amount of time to run. > >> > >> If you needed the output to be displayed on a webpage, you can write the > >> progress to a file, and then have a php webpage that reads the file, and > >> using ajax or whatever, refresh the content. > >> > >> good luck in your script, and if you still run it from the browser, and > >> need to output to a file, then i would continually be writing content to > >> that file, every time you do soemthing, or start another part of the > >> script so you know EXACTLY where you are, at all times... > >> > >> Steve > >> > > > > Hi Steve, > > > > Thanks for the tips. To answer your queries, I don't mind using CLI. How do > > I then ensure the messages, error or otherwise, output by the library I use, > > show up in the file I'm outputting to? Please note that I only make calls to > > the functions and object methods from this library and error or success > > messages are probably echo'd by the code from the library. > > > > I believe some context is in order. I am actually sending an email to a > > large number of our customers (around 10,000), each with the customer's > > name. > > > > My script does output a simple success or failure message. The library > > outputs more technical info. All I would like to know is which email got > > sent and which one failed. As you point out, I could write the success / > > failure messages to a file, but, I would also like to capture the messages > > output by the library. > > > > Thanks and regards, > > Ferdi > > > > I would log the success/failure with the data (assuming it is coming from a DB). > > If not, you could use a simple file_put_contents($filename, date('r') > . $text . PHP_EOL, FILE_APPEND); > > That would append 1 line of text at a time to the file. Using tail on > that file would show you the last work done (and when it was done). > > > -- > Richard Quadling > Twitter : EE : Zend > @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY > if you're using a linux based server, you could log (like Richard said) each success / failure to the file, or each to its own success / failure file, and then if you want to watch the, you could just do a tail -f of the file, to see what is it doing (sometimes having it scroll is pretty handy i find)... it wouldn't be hard to write a web-based 'tail -f' page, so you can track the progress from anywhere you wanted :) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php