Re: [PHP] script timeout

2007-04-25 Thread Tijnema !

On 4/25/07, Henning Eiben [EMAIL PROTECTED] wrote:

Hi,

I have a small sample-application, that uses smarty for the presentation
layer. Unfortunately I might encounter script-timeouts (not necessarily
from smarty, could also be the DB-connection or something). In this case
I would like to return an appropriate HTTP status-code (might be 500 or
something). Right now I just receive a blank page, as well as a HTTP
status-code of 200, which would indicate that everything is OK!

So what do I need to do?


I don't think this is possible in PHP. But i guess you need to do
something in Apache, to return some special error message. A thing to
keep in mind:
PHP max_execution_time set in php.ini or set with set_time_limit does
not affect system calls, such as database operations.
So, you'd be better off setting the time limit in Apache, and do some
stuff with Apache configuration files to return something.

Of course, every Apache could be replaced by IIS in above text :)

Tijnema

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] script timeout

2007-04-25 Thread Henning Eiben
Tijnema ! wrote:

 I have a small sample-application, that uses smarty for the presentation
 layer. Unfortunately I might encounter script-timeouts (not necessarily
 from smarty, could also be the DB-connection or something). In this case
 I would like to return an appropriate HTTP status-code (might be 500 or
 something). Right now I just receive a blank page, as well as a HTTP
 status-code of 200, which would indicate that everything is OK!

 So what do I need to do?

 I don't think this is possible in PHP. But i guess you need to do
 something in Apache, to return some special error message. A thing to
 keep in mind:
 PHP max_execution_time set in php.ini or set with set_time_limit does
 not affect system calls, such as database operations.
 So, you'd be better off setting the time limit in Apache, and do some
 stuff with Apache configuration files to return something.

Well, looking at my error.log in my PHP directory tells me, that
several php-files exceeded maximum scripting time. That's why I asked.

And I observed receiving a blank page, which is not satisfying ... so
what would I do in Apache (or IIS) to get an error-code (HTTP code that is)?




-- 
... Black holes suck.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] script timeout

2007-04-25 Thread Stut

Henning Eiben wrote:

Tijnema ! wrote:


I have a small sample-application, that uses smarty for the presentation
layer. Unfortunately I might encounter script-timeouts (not necessarily
from smarty, could also be the DB-connection or something). In this case
I would like to return an appropriate HTTP status-code (might be 500 or
something). Right now I just receive a blank page, as well as a HTTP
status-code of 200, which would indicate that everything is OK!

So what do I need to do?


I don't think this is possible in PHP. But i guess you need to do
something in Apache, to return some special error message. A thing to
keep in mind:
PHP max_execution_time set in php.ini or set with set_time_limit does
not affect system calls, such as database operations.
So, you'd be better off setting the time limit in Apache, and do some
stuff with Apache configuration files to return something.


Well, looking at my error.log in my PHP directory tells me, that
several php-files exceeded maximum scripting time. That's why I asked.

And I observed receiving a blank page, which is not satisfying ... so
what would I do in Apache (or IIS) to get an error-code (HTTP code that is)?


Use register_shutdown_function to, erm, register a shutdown function. 
Call ob_start at the very top of the script. Initialise $finished to 
false on the line after that. At the end of the script set it to true. 
If your shutdown function gets called and $finished is false then the 
script did not finish. Call ob_end_clean and output the header/body to 
return the HTTP error code you want.


-Stut

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] script timeout

2007-04-25 Thread Stut

Stut wrote:

Henning Eiben wrote:

Tijnema ! wrote:

I have a small sample-application, that uses smarty for the 
presentation

layer. Unfortunately I might encounter script-timeouts (not necessarily
from smarty, could also be the DB-connection or something). In this 
case

I would like to return an appropriate HTTP status-code (might be 500 or
something). Right now I just receive a blank page, as well as a HTTP
status-code of 200, which would indicate that everything is OK!

So what do I need to do?


I don't think this is possible in PHP. But i guess you need to do
something in Apache, to return some special error message. A thing to
keep in mind:
PHP max_execution_time set in php.ini or set with set_time_limit does
not affect system calls, such as database operations.
So, you'd be better off setting the time limit in Apache, and do some
stuff with Apache configuration files to return something.


Well, looking at my error.log in my PHP directory tells me, that
several php-files exceeded maximum scripting time. That's why I asked.

And I observed receiving a blank page, which is not satisfying ... so
what would I do in Apache (or IIS) to get an error-code (HTTP code 
that is)?


Use register_shutdown_function to, erm, register a shutdown function. 
Call ob_start at the very top of the script. Initialise $finished to 
false on the line after that. At the end of the script set it to true. 
If your shutdown function gets called and $finished is false then the 
script did not finish. Call ob_end_clean and output the header/body to 
return the HTTP error code you want.


Oh, I forgot to add that you should look at the set_time_limit function 
as a possible means to avoiding the script ending. When I write a script 
that will sit in a loop that could potentially loop a lot I'll call 
set_time_limit with a reasonable time allowed for a single loop 
execution. This means as long as the script is actually doing something 
it will not time out.


-Stut

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] script timeout

2007-04-25 Thread Richard Lynch
On Wed, April 25, 2007 4:27 am, Henning Eiben wrote:
 I have a small sample-application, that uses smarty for the
 presentation
 layer. Unfortunately I might encounter script-timeouts (not
 necessarily
 from smarty, could also be the DB-connection or something). In this
 case
 I would like to return an appropriate HTTP status-code (might be 500
 or
 something). Right now I just receive a blank page, as well as a HTTP
 status-code of 200, which would indicate that everything is OK!

 So what do I need to do?

http://php.net/set_error_handler
http://php.net/header

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Script timeout?

2004-01-27 Thread memoimyself
Hello Ben,

On 27 Jan 2004 at 9:27, Ben Ramsey wrote:

 I'm trying to run a query against a database with a PHP script that 
 cycles through each record (about 4,000+) and sends and e-mail to them 
 if they have an e-mail address present.  The problem is that everytime I 
 do this, it processes about 430 records and stops.  There is no error 
 message generated.  Could this be due to a script timeout?  If so, how 
 do I raise the timeout value?

Look up set_time_limit in the PHP manual. Also, consider retrieving all the records 
first 
with a single db query, storing all e-mails in an array, and then sending out the 
e-mails 
in a separate operation. Why query your db 4000+ times when you can query it only  
once?

Good luck,

Erik

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Script timeout?

2004-01-27 Thread Ben Ramsey
Ah... I was trying to lookup the word timeout, which was giving me 
nothing.  Thanks!  Also, shouldn't I be receiving an error message if 
the script is, in fact, timing out?  I have checked display_errors and 
it is turned on.



[EMAIL PROTECTED] wrote:

Hello Ben,

On 27 Jan 2004 at 9:27, Ben Ramsey wrote:


I'm trying to run a query against a database with a PHP script that 
cycles through each record (about 4,000+) and sends and e-mail to them 
if they have an e-mail address present.  The problem is that everytime I 
do this, it processes about 430 records and stops.  There is no error 
message generated.  Could this be due to a script timeout?  If so, how 
do I raise the timeout value?


Look up set_time_limit in the PHP manual. Also, consider retrieving all the records first 
with a single db query, storing all e-mails in an array, and then sending out the e-mails 
in a separate operation. Why query your db 4000+ times when you can query it only  
once?

Good luck,

Erik
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Script timeout?

2004-01-27 Thread Marek Kilimajer
set_time_limit()

This function has no effect in safe mode, you will need another 
workaround, for example send fisrt 400 emails and redirect the browser 
to send next 400 emails and so on untill you are done.

Ben Ramsey wrote:

I'm trying to run a query against a database with a PHP script that 
cycles through each record (about 4,000+) and sends and e-mail to them 
if they have an e-mail address present.  The problem is that everytime I 
do this, it processes about 430 records and stops.  There is no error 
message generated.  Could this be due to a script timeout?  If so, how 
do I raise the timeout value?

-Ben

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Script timeout?

2004-01-27 Thread Marek Kilimajer
You should. I know I did in older version of php, now I don't.

Ben Ramsey wrote:

Ah... I was trying to lookup the word timeout, which was giving me 
nothing.  Thanks!  Also, shouldn't I be receiving an error message if 
the script is, in fact, timing out?  I have checked display_errors and 
it is turned on.



[EMAIL PROTECTED] wrote:

Hello Ben,

On 27 Jan 2004 at 9:27, Ben Ramsey wrote:


I'm trying to run a query against a database with a PHP script that 
cycles through each record (about 4,000+) and sends and e-mail to 
them if they have an e-mail address present.  The problem is that 
everytime I do this, it processes about 430 records and stops.  There 
is no error message generated.  Could this be due to a script 
timeout?  If so, how do I raise the timeout value?


Look up set_time_limit in the PHP manual. Also, consider retrieving 
all the records first with a single db query, storing all e-mails in 
an array, and then sending out the e-mails in a separate operation. 
Why query your db 4000+ times when you can query it only  once?

Good luck,

Erik


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Script timeout?

2004-01-27 Thread Ben Ramsey
I'm running PHP 5.0 beta 3, and I have seen script timeout errors 
before.  It's just odd that I wasn't receiving them this time. 
Increasing the timeout helped, but didn't fully correct the problem.  I 
just kept changing the SQL statement to WHERE user_key = [id number 
where it left off] so that it would send in batches and not send to the 
same people twice.

I didn't code this originally or I would've used a SQL JOIN to combine 
two tables of data instead of hitting the database a second time for 
each record encountered as my other programmer did.  So, I'm going to 
revise the scripts for future use and then do as someone said and save 
all the e-mail addresses to an array (and perhaps even free the result 
set) before sending.

Thanks!

-Ben

Marek Kilimajer wrote:

You should. I know I did in older version of php, now I don't.

Ben Ramsey wrote:

Ah... I was trying to lookup the word timeout, which was giving me 
nothing.  Thanks!  Also, shouldn't I be receiving an error message if 
the script is, in fact, timing out?  I have checked display_errors 
and it is turned on.



[EMAIL PROTECTED] wrote:

Hello Ben,

On 27 Jan 2004 at 9:27, Ben Ramsey wrote:


I'm trying to run a query against a database with a PHP script that 
cycles through each record (about 4,000+) and sends and e-mail to 
them if they have an e-mail address present.  The problem is that 
everytime I do this, it processes about 430 records and stops.  
There is no error message generated.  Could this be due to a script 
timeout?  If so, how do I raise the timeout value?




Look up set_time_limit in the PHP manual. Also, consider retrieving 
all the records first with a single db query, storing all e-mails in 
an array, and then sending out the e-mails in a separate operation. 
Why query your db 4000+ times when you can query it only  once?

Good luck,

Erik



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


RE: [PHP] Script timeout?

2004-01-27 Thread jon roig
Two ways we deal with long running scripts like this are:
1) Run it from the command line. Usually, PHP drives web pages... But it
can be used as a scripting language just like perl. Beginning the script
with set_time_limit(0) kills the timeout. Also, running from the command
line gets around all the weird browser display issues that one sometimes
sees.
2) Mark your place as you go. Maybe include a field called something
like lastSent. When each email goes out, mark it. That way, you can
recover it later if something happens.

-- jon

---
jon roig
web developer
email: [EMAIL PROTECTED]
phone: 888.230.7557



-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, January 27, 2004 7:36 AM
To: [EMAIL PROTECTED]
Subject: Re: [PHP] Script timeout?


Hello Ben,

On 27 Jan 2004 at 9:27, Ben Ramsey wrote:

 I'm trying to run a query against a database with a PHP script that
 cycles through each record (about 4,000+) and sends and e-mail to them

 if they have an e-mail address present.  The problem is that everytime
I 
 do this, it processes about 430 records and stops.  There is no error 
 message generated.  Could this be due to a script timeout?  If so, how

 do I raise the timeout value?

Look up set_time_limit in the PHP manual. Also, consider retrieving all
the records first 
with a single db query, storing all e-mails in an array, and then
sending out the e-mails 
in a separate operation. Why query your db 4000+ times when you can
query it only  
once?

Good luck,

Erik

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.564 / Virus Database: 356 - Release Date: 1/19/2004
 

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.564 / Virus Database: 356 - Release Date: 1/19/2004
 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Script timeout

2001-08-23 Thread Christian Reiniger

On Wednesday 22 August 2001 17:59, Julian Wood wrote:
 I have a script which has to do a *lot* of work. In fact, it times out
 after 300 seconds, but is only about half done at that point. So I
 tried using set_time_limit(0) to no avail (php is *not* running in safe
 mode). So next I tried this directive in the apache config file:
 php_value max_execution_time 12000 (and various other values too). Now
 this changed the value of the constant correctly as reported by
 phpinfo(), but not as reported by get_cfg_var(max_execution_time),
 which still reported the default 30s. Empirically, the script would
 still time out at exactly 300 seconds, as before. So, any idea what is
 going on? Why timeout at 300s instead of the 30s or the 12000s which
 are the only two values reported? Any other workarounds? This is php
 4.0

Looks like some HTTP timeout, i.e. either Apache or the browser is 
getting bored. Try outputting something from time to time.

-- 
Christian Reiniger
LGDC Webmaster (http://lgdc.sunsite.dk/)

Install once, run forever. Linux.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] Script timeout

2001-08-23 Thread Dave

flush is your friend

-Original Message-
From: Christian Reiniger [mailto:[EMAIL PROTECTED]]
Sent: Thursday, August 23, 2001 5:42 AM
To: Julian Wood; [EMAIL PROTECTED]
Subject: Re: [PHP] Script timeout


On Wednesday 22 August 2001 17:59, Julian Wood wrote:
 I have a script which has to do a *lot* of work. In fact, it times out
 after 300 seconds, but is only about half done at that point. So I
 tried using set_time_limit(0) to no avail (php is *not* running in safe
 mode). So next I tried this directive in the apache config file:
 php_value max_execution_time 12000 (and various other values too). Now
 this changed the value of the constant correctly as reported by
 phpinfo(), but not as reported by get_cfg_var(max_execution_time),
 which still reported the default 30s. Empirically, the script would
 still time out at exactly 300 seconds, as before. So, any idea what is
 going on? Why timeout at 300s instead of the 30s or the 12000s which
 are the only two values reported? Any other workarounds? This is php
 4.0

Looks like some HTTP timeout, i.e. either Apache or the browser is 
getting bored. Try outputting something from time to time.

-- 
Christian Reiniger
LGDC Webmaster (http://lgdc.sunsite.dk/)

Install once, run forever. Linux.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] Script timeout

2001-08-23 Thread Johnson, Kirk

Why timeout at 300s instead of the 30s or the 12000s which
  are the only two values reported?
 
 Looks like some HTTP timeout, i.e. either Apache or the browser is 
 getting bored. Try outputting something from time to time.

Can anybody point me to information on all the possible HTTP timeouts there
are (Apache, browser, ???), or care to discuss it here? We occasionally see
timeouts that are not due to PHP, and I'm wondering where they are coming
from.

TIA

Kirk

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Script timeout with set_time_limit(0);

2001-05-17 Thread Plutarck

Try setting the timeout to some high setting, beyond how long you need it to
run.

Often PHP just won't run for a really long time, for reasons I don't know.
It just occassionally decides it's done, but I know it can go for longer
than 3 days (phpIRC often lives that long and longer) so that probably isn't
your problem.

Try the function that gets how long your timeout is set to (can't recall the
name atm) before and after you set it and see what it says.


Plutarck

JFL [EMAIL PROTECTED] wrote in message
9e0bga$g7t$[EMAIL PROTECTED]">news:9e0bga$g7t$[EMAIL PROTECTED]...
 When I start a script like this :

   $fp = fsockopen($host, $port, $errno, $errstr, 30);
   if ($fp) {
$fputs_str  = GET .$path. HTTP/1.1\r\n;
$fputs_str .= Host: .$host.\r\n;
$fputs_str .= \r\n;
   fputs($fp, $fputs_str);
fclose($fp);
   }

 The script will run for some time. But then ends. I have set
  set_time_limit(0);
  ignore_user_abort(1);
 but the script does not run through.

 What can I do ?
 --
 [ www.eksperten.dk ] Scandinavias biggest IT forum.



 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]