473,587 Members | 2,508 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3650
> 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.ne t> 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 "chronoscri pt", 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.ne t> 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 "chronoscri pt", 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 "personalis ed"?

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*@WINDOZEdig iserv.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 "personalis ed"?

(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.ne t> wrote:
Ian.H wrote:
(snip)
Damien, are the bodies of the mail the same? or are they "personalis ed"?(snip)

Unfortunatel y, 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
2912
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 processing and creating 500 thumbnails. Is there anything I can do to avoid this error? Thank you John
10
5394
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 maximum execution time of scripts. So, the script stops right in the middle of doing the update. On top of that, I am trying to make code that I...
7
7599
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 inserting a new record. I am using Application.Lock and .Unlock together with an application variable to negotiate access to the DB routine to one...
2
3773
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 produce two messages having the same message digest. That conjecture is false, as demonstrated by Wang, Feng, Lai and Yu in 2004 . Just recently,...
11
5275
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 4-month old C#/MC++ .NET project project. I'd like to thank in advance anyone who takes the time to read and/or respond to this message. At a couple...
2
1581
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 page presentations, it works well. However, I have a couple of screen scrape / import routines that can take minutes, even hours, to complete....
73
7387
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 yield a value that exceeds the range of an unsigned long." 6.5.6: "With the introduction of the long long and extended integer
6
1443
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
19167
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 communications. http://community.lokad.com/PhpSalesForecasting.ashx Yet, in shared hosting with short PHP execution timeouts, our script may not...
0
7923
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7852
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8216
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8349
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
8221
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6629
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5719
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3882
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1192
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.