Page 1 of 1

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

Posted: Thu May 17, 2007 6:12 pm
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.

Posted: Thu May 17, 2007 6:14 pm
by RobertGonzalez
Could it perhaps be a max memory limit issue?

Don't think so

Posted: Thu May 17, 2007 6:25 pm
by gordon72
The script completed, all the emails were sent. If there was a memory limit reached the script would have terminated (I think)

Posted: Thu May 17, 2007 6:34 pm
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.

Posted: Thu May 17, 2007 6:45 pm
by Weirdan
As far as I remember there's per-process limit on the amount of file handles imposed by the OS.

If you are keen - this is the script

Posted: Thu May 17, 2007 6:55 pm
by gordon72

Weirdran - I suspect that could be it!

Posted: Thu May 17, 2007 7:05 pm
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

Posted: Thu May 17, 2007 7:07 pm
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?

Posted: Thu May 17, 2007 7:10 pm
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.

Other lines also failed.

Posted: Thu May 17, 2007 7:35 pm
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!

Posted: Thu May 17, 2007 7:55 pm
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'];

Script cannot be browser accessed!

Posted: Thu May 17, 2007 8:50 pm
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