Is there a limit to no. of file handlers a script can use?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
gordon72
Forum Newbie
Posts: 7
Joined: Thu May 17, 2007 5:54 pm

Is there a limit to no. of file handlers a script can use?

Post by gordon72 »

I sometimes have to do large mailouts (to subscribed addresses). I have a system where I build a mailout list from the wesbite administration tool, then send have the web-script call a background script to do the mailout. The background script reports back by writing an XML file which an ajax script from the browser accesses regularly.

The system works well, and has successfully sent throusands of emails for newsletters etc.

the most recent one I ran, something strange happenned. It was a very large list, and while the script did completely send all the emails (as confirmed by grepping the mail log) it stopped rewriting the XML file.

I have a custom error handler that should report any major PHP errors, but received nothing.

It had successfully rewritten the XML file about 2600 times when it stopped working.

After the last email is sent it should also sleep 15 seconds than delete the XML file (giving enough time for the Ajax script to get the last report), however it did not do this either.

I am wondering if there is an upper limit on how many times a PHP script can open a file handler? As I am closing the handler after each write.

Does anyone know about file handlers, and if they have a script limit? If so, I bet the guy who programmed the PHP file handler never thought anyone would ever use that limit!

PS - I do not endorse SPAM! this is for legitimate subscribed mailing lists only.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Could it perhaps be a max memory limit issue?
gordon72
Forum Newbie
Posts: 7
Joined: Thu May 17, 2007 5:54 pm

Don't think so

Post by gordon72 »

The script completed, all the emails were sent. If there was a memory limit reached the script would have terminated (I think)
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Is there any chance that we can see the code where the XML writing stopped? Maybe there was a trigger that is not being fired somewhere.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

As far as I remember there's per-process limit on the amount of file handles imposed by the OS.
gordon72
Forum Newbie
Posts: 7
Joined: Thu May 17, 2007 5:54 pm

If you are keen - this is the script

Post by gordon72 »

gordon72
Forum Newbie
Posts: 7
Joined: Thu May 17, 2007 5:54 pm

Weirdran - I suspect that could be it!

Post by gordon72 »

Operating system limit sounds likely - Either I look into this limit, or change the way the script works. I could leave the one handler open I suppose, however not sure if this is a good idea considering the script runs for hours. Wondering also if apache can access a file that a file handler has open - guess I will just have to find out!

PS - Weirdran - are you a mineralogist or do you just like that image? brings back memories of 2nd year geology.

Thanks for your help
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Are you sure that there is nothing that could cause this line:

Code: Select all

if ( ($int_total_sent - (floor( $int_total_sent/REPORT_INTERVAL ) * REPORT_INTERVAL)) == 0  )
to not equal 0?

Edit | I am wondering too if there is a chance that the fopen() call failed? I notice there is not error handling on that. Have you had a look at your server error log?
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

PS - Weirdran - are you a mineralogist or do you just like that image? brings back memories of 2nd year geology.
It's a pic of squashed hedgehog + some filter, chosen randomly in Photoshop.
gordon72
Forum Newbie
Posts: 7
Joined: Thu May 17, 2007 5:54 pm

Other lines also failed.

Post by gordon72 »

I should have use the remainder function! so many functions in PHP!

Anyway, even if there is a logic error in that line, that would cause me to never again get that equation to equal zero, I should still have got a report written when the loop was complete, then the unlink lines should also have executed.

PS - Squashed Hedghog? looks more like a Badger to me!
nickvd
DevNet Resident
Posts: 1027
Joined: Thu Mar 10, 2005 5:27 pm
Location: Southern Ontario
Contact:

Post by nickvd »

While certainly not the cause of your problem, it may be the cause of a server break-in...


SQL INJECTION:

Code: Select all

$sql .= "INNER JOIN search_results ON search_results.contact_id = ".$config['contact']['table'].".".$config["contact"]["key"]." AND search_id = ".$_GET['search_id'];
gordon72
Forum Newbie
Posts: 7
Joined: Thu May 17, 2007 5:54 pm

Script cannot be browser accessed!

Post by gordon72 »

I assure you, this script cannot be accessed directly by a browser/HTTP request, it is a background script.

NB - globals are always off and magic quotes turned on
Post Reply