473,394 Members | 1,787 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Long execution time for a script: avoid error messages ?

Hello to all,
I've written a script that take quite a long time to execute (email
sending). Last time I ran it, PHP gave me a "execution time limit
exceeded" (or something like that), so I changed the value in php.ini.

Now, the questions are :
- How can I make sure I'm not going to have problems when execution time
lengthens still ? I'm afraid to set too high a time limit in case other
scripts run astray.
- Can I "break" the job into "batches" ?

I'm going to try to see what takes som much time, but I'm afraid it is
always going to be long.

Anyway, thanks in advance for any help !

BR,
Damien
Jul 17 '05 #1
7 3631
> Now, the questions are :
- How can I make sure I'm not going to have problems when execution time
lengthens still ? I'm afraid to set too high a time limit in case other
scripts run astray.
I think that depends on what your script does... in case you've got a loop
somewhere
you could save a timestamp when the script starts (before the loop) and
within you
compare the actual timestamp with the first one... of course this also costs
time... I've never
tried that but I think it could work

- Can I "break" the job into "batches" ?


Neither tried this, but what about - if your time-stamp-comparison tells you
that the script is about
to stop due to a timeout, you send a header(Location.
path_to_script.php?id=5) to let your
script know that it should continue with id number 5
Has anyone experiences with such a strategy??

Greetings,

Gert.
Jul 17 '05 #2
On Mon, 13 Sep 2004 11:56:25 +0200, Damien <tr**@bidule.net> wrote:
Hello to all,
I've written a script that take quite a long time to execute (email
sending). Last time I ran it, PHP gave me a "execution time limit
exceeded" (or something like that), so I changed the value in php.ini.

Now, the questions are :
- How can I make sure I'm not going to have problems when execution time
lengthens still ? I'm afraid to set too high a time limit in case other
scripts run astray.
- Can I "break" the job into "batches" ?

I'm going to try to see what takes som much time, but I'm afraid it is
always going to be long.

Anyway, thanks in advance for any help !

BR,
Damien

You could break it into batches.. I did this a week ago for a client but
may depend on exactly what kind of queries are being run. If they're
relatively "simple"[1] there should be no problem doing that.

I wrote a simple "pagination" function that then worked out the starting
record for the SQL query and displayed a 'prev | next' page link (I
actually used the code from a Smarty plugin I wrote.. the 'prev' link
may not be necessary etc) but this then worked no problem for about
15,000 entries =)

Regards,

Ian
[1]: Referring to "simple" here rather than one query I had that didn't
work so well like this as it was a recursive loop to query too but if
it's "straight forward" (maybe a better description than "simple") there
should be no real issues.

--
Ian.H
digiServ Network
London, UK
http://digiserv.net/
Jul 17 '05 #3
Ian.H a écrit :
(snip)

You could break it into batches.. I did this a week ago for a client but
may depend on exactly what kind of queries are being run. If they're
relatively "simple"[1] there should be no problem doing that.
Actually, based on my "chronoscript", what's costing me time is the
mail() function, not the queries I make in order to prepare the mail
being sent.

I wrote a simple "pagination" function that then worked out the starting
record for the SQL query and displayed a 'prev | next' page link (I
actually used the code from a Smarty plugin I wrote.. the 'prev' link
may not be necessary etc) but this then worked no problem for about
15,000 entries =)

Problem with my script is that the loop generates the elements from what
is posted by a form: recipient list, message. So I'm afraid I'm going to
have troubles breaking the receipients into batches unless I store them
in a table first.

Hmmm, guess I've got some DB filling ahead ;) . Any other idea ?

Thanks for the tips anyway !
Damien
--
"And you told them that servers were like old people - you put them to
sleep at night and there's a few dead ones in the morning?"
BOFH
Jul 17 '05 #4
On Mon, 13 Sep 2004 17:55:36 +0200, Damien <tr**@bidule.net> wrote:
Ian.H a écrit :
(snip)

You could break it into batches.. I did this a week ago for a client but
may depend on exactly what kind of queries are being run. If they're
relatively "simple"[1] there should be no problem doing that.


Actually, based on my "chronoscript", what's costing me time is the
mail() function, not the queries I make in order to prepare the mail
being sent.

I wrote a simple "pagination" function that then worked out the starting
record for the SQL query and displayed a 'prev | next' page link (I
actually used the code from a Smarty plugin I wrote.. the 'prev' link
may not be necessary etc) but this then worked no problem for about
15,000 entries =)

Problem with my script is that the loop generates the elements from what
is posted by a form: recipient list, message. So I'm afraid I'm going to
have troubles breaking the receipients into batches unless I store them
in a table first.

Hmmm, guess I've got some DB filling ahead ;) . Any other idea ?

Thanks for the tips anyway !
Damien

Damien, are the bodies of the mail the same? or are they "personalised"?

I'm assuming that you're firing off multiple mails using mail() sending
by only the 'TO' header. Have you thought about the loop generating a CC
header? (or BCC.. but not sure how many these days reject BCC'd mail due
to abuse). This would result in just one mail actually being processed
to be sent but with multiple recipients which may cure your mail()
bottleneck.

There are a few issues to maybe take into account here though regarding
my suggestions.. as mentioned, BCC has become an "easy abuse method" and
some admins drop these mails. Likewise, too many recipients in the CC
header and the mail will also be rejected.

Not knowing the exact workings of your structure.. these ideas maybe
null&void.. but _might_ be an alternative option =)

Regards,

Ian

--
Ian.H
digiServ Network
London, UK
http://digiserv.net/
Jul 17 '05 #5
On Mon, 13 Sep 2004 16:24:09 GMT, Ian.H <ia*@WINDOZEdigiserv.net> wrote:
[ snip ]

There are a few issues to maybe take into account here though regarding
my suggestions.. as mentioned, BCC has become an "easy abuse method" and
some admins drop these mails. Likewise, too many recipients in the CC
header and the mail will also be rejected.

^^^^
[ snip ]
Oops! That should really be "may" rather than "will" =)

Regards,

Ian

--
Ian.H
digiServ Network
London, UK
http://digiserv.net/
Jul 17 '05 #6
Ian.H wrote:
(snip)
Damien, are the bodies of the mail the same? or are they "personalised"?

(snip)

Unfortunately, no... I'm trying to customize the message body
(recipient's name, trackers...) so I have to process it for every person.

Hmmm, I guess I'm going to design a temp table that holds the job ID and
the info for the recipients. Then I'll query this table in "batches" (eg
10 by 10 or so). Actually, this may make my life easier in several aspects.

Has anybody ever implemented something like that ? Anything I should be
aware of ? Like security, etc ? Not that anybody knows ANY PHP of SQL,
but... "A warned developer is worth 2, even when he's twins" :)

Thanks again for the input, your ideas on BCC-ing are pretty sensible,
I'm sure. As for CC-ing... I've just received the whole address book of
one of my suppliers informing us of a change of email :)

BR,
Damien
--
Jul 17 '05 #7
On Mon, 13 Sep 2004 19:19:35 +0200, Damien <tr**@bidule.net> wrote:
Ian.H wrote:
(snip)
Damien, are the bodies of the mail the same? or are they "personalised"?(snip)

Unfortunately, no... I'm trying to customize the message body
(recipient's name, trackers...) so I have to process it for every person.

Hmmm, I guess I'm going to design a temp table that holds the job ID and
the info for the recipients. Then I'll query this table in "batches" (eg
10 by 10 or so). Actually, this may make my life easier in several aspects.

Fair enough.. sometimes I've found a little more time spent on the
structure makes future development much easier and quicker.. hope all
goes well =)

Has anybody ever implemented something like that ? Anything I should be
aware of ? Like security, etc ? Not that anybody knows ANY PHP of SQL,
but... "A warned developer is worth 2, even when he's twins" :)

Can't say I personally have.. any "mailing list" style mails I use I run
through Mailman (but obviously this doesn't work for all situations).

Thanks again for the input, your ideas on BCC-ing are pretty sensible,
I'm sure. As for CC-ing... I've just received the whole address book of
one of my suppliers informing us of a change of email :)

BR,
Damien

Heh.. np =)

I actually drop mail here with a CC header of more than 10 addresses..
but I'm a draconian bastard when it comes to my mailservers (although I
do whitelist upon customer request if viable =) ) with only 1-2 spam
mails per couple of months received now (for all accounts, including
customers.. which are then squashed (well, tagged) by SpamAssassin and
then escalated to the DNSbl) rather than the 500+ to a single account I
used to get.

Regards,

Ian

--
Ian.H
digiServ Network
London, UK
http://digiserv.net/
Jul 17 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: John | last post by:
I am trying to create thumbnails from 2500 pictures. But I always get a Maximum execution time of 30 seconds exceeded" at the statement with the method with imagejpeg or imagedestroy after...
10
by: Doug | last post by:
I have a script that does a huge database update, which takes a long time. However, the host I am running on (and I suspect most hosts) are running in "safe mode." This means I cannot change the...
7
by: Dr. Know | last post by:
I am working on an ASP page that writes to several databases, ranging from MDBs to x-base. One of the tasks involves using an existing highest value from the DB and incrementing it before...
2
by: Bryan Olson | last post by:
The current Python standard library provides two cryptographic hash functions: MD5 and SHA-1 . The authors of MD5 originally stated: It is conjectured that it is computationally infeasible to...
11
by: Ken Durden | last post by:
I am in search of a comprehensive methodology of using these two object cleanup approaches to get rid of a number of bugs, unpleasantries, and cleanup-ordering issues we currently have in our...
2
by: Brent | last post by:
Like many sites, mine has a standard "look" -- a template, if you will -- that visitors see on each page. I've tried to keep the code and HTML separate to the extent possible, and for most standard...
73
by: Yevgen Muntyan | last post by:
Hey, I was reading C99 Rationale, and it has the following two QUIET CHANGE paragraphs: 6.5.3.4: "With the introduction of the long long and extended integer types, the sizeof operator may...
6
by: Moses | last post by:
Hi All, How to avoid the execution of a function at the time of defining. Here i am giving the details. I am creating the following div container through DOM.
2
by: Joannes Vermorel | last post by:
We have developed an open-source eCommerce sales forecasting add-on in PHP (see link below) that requires usually more than a few seconds to complete because the process involves some Web Services...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.