Re: [PHP] Too many open files

2012-08-12 Thread Al



On 8/10/2012 12:02 PM, Daniel Brown wrote:

On Fri, Aug 10, 2012 at 10:22 AM, Robert Cummings rob...@interjinn.com wrote:

On 12-08-09 08:01 PM, Al wrote:

I can't find a way to see what files could be open or what the limit is.

Site is on a shared server, cPanel.


^
THIS is probably your problem. Too many open files indicates that either the
user OR the OS has reached its limit of allowed open file handles. Open
files are those used by the OS and every user on the shared server. The
setting can be changed but you'll need an administrator to increase the
number of allowed open files. I suspect it's at the OS level if indeed you
only have 100 files open (though you likely have more due to files opened
for you by the OS or whatnot.


 Rob is exactly right.  This is managed via the kernel and ulimit,
to prevent excessive resource usage.  Often it's a temporary problem,
but if it consistently occurs, your host may either be improperly
configured or, more likely, overselling resources.



I've checked carefully and my code does not have any open files, I obviously 
can't check the OS, etc.


I'm using Pear Mail_mime()to batch send emails.  The problem is created when my 
batch exceeds about 36 sends.  I have several mail functions which all iterate 
this function for each recipient.

emailPearSend($mime, $headers, $bodyText, $attachedFile = null, $imgFile = null)

I did have the $mime = new Mail_mime(\r\n); in emailPearSend(), which meant it 
was called for every recipient. I tried moving it out of the calling function so 
it would only be called one time for each batch, and I send the $mime as a 
function arg.  Didn't help.


I'm off to get the host to check and fix the open files limit.

Off the subject a bit. What does PHP do with repeated new classes, e.g.
$mime = new Mail_mime   Are they simply ignored or are additional new instances 
created. PHP won't let you duplicate function names.






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



Re: [PHP] Too many open files

2012-08-12 Thread Matijn Woudt
On Fri, Aug 10, 2012 at 6:02 PM, Daniel Brown danbr...@php.net wrote:
 On Fri, Aug 10, 2012 at 10:22 AM, Robert Cummings rob...@interjinn.com 
 wrote:
 On 12-08-09 08:01 PM, Al wrote:
 I can't find a way to see what files could be open or what the limit is.

 Site is on a shared server, cPanel.

^
 THIS is probably your problem. Too many open files indicates that either the
 user OR the OS has reached its limit of allowed open file handles. Open
 files are those used by the OS and every user on the shared server. The
 setting can be changed but you'll need an administrator to increase the
 number of allowed open files. I suspect it's at the OS level if indeed you
 only have 100 files open (though you likely have more due to files opened
 for you by the OS or whatnot.

 Rob is exactly right.  This is managed via the kernel and ulimit,
 to prevent excessive resource usage.  Often it's a temporary problem,
 but if it consistently occurs, your host may either be improperly
 configured or, more likely, overselling resources.


It's not uncommon for shared hosters to host over a 1000 websites on a
single host, so reaching the limits is not that hard anymore. Best
solution in this case (though your hosting provider might not like
it), is just retry until the open succeeds and only then continue with
the next file.

- Matijn

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



Re: [PHP] Too many open files

2012-08-10 Thread Matijn Woudt
On Fri, Aug 10, 2012 at 5:36 AM, Jim Lucas li...@cmsws.com wrote:
 On 8/9/2012 5:01 PM, Al wrote:

 Getting Too many open files error when processing an email batch
 process.

 I've looked extensively and can't find more than about 100 files that
 could be open.  All my fetching is with get_file_contents();


 Why not use fopen() and other related functions to open/grap/close your
 batch of files?

 You could replace a call like this:

 $data = file_get_contents($filename);

 with this:

 if ( $fh = fopen($filename, 'r') ) {
   $data = fread($fh, filesize($filename));
   fclose($fh);
 }

 This should take care of your issue.

 Jim Lucas

Why on earth would you want to reinvent the wheel? There's no point in
saying that fopen/fread/fclose is better, in fact, let me quote from
the manual page of file_get_contents:
file_get_contents() is the preferred way to read the contents of a
file into a string. It will use memory mapping techniques if supported
by your OS to enhance performance.

If your solution would fix the problem (I doubt, but ok), then you
should report a bug to the PHP devs that file_get_contents is broken.

To the OP: Show some code, there might be something else.

- Matijn

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



Re: [PHP] Too many open files

2012-08-10 Thread Robert Cummings

On 12-08-09 08:01 PM, Al wrote:

Getting Too many open files error when processing an email batch process.

The batch size is actually rather small and the email text is small likewise.

I've looked extensively and can't find more than about 100 files that could be
open.  All my fetching is with get_file_contents();

I can't find a way to see what files could be open or what the limit is.

Site is on a shared server, cPanel.

   ^
THIS is probably your problem. Too many open files indicates that either 
the user OR the OS has reached its limit of allowed open file handles. 
Open files are those used by the OS and every user on the shared server. 
The setting can be changed but you'll need an administrator to increase 
the number of allowed open files. I suspect it's at the OS level if 
indeed you only have 100 files open (though you likely have more due to 
files opened for you by the OS or whatnot.


Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

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



Re: [PHP] Too many open files

2012-08-10 Thread Robert Cummings

On 12-08-10 02:49 AM, Matijn Woudt wrote:

On Fri, Aug 10, 2012 at 5:36 AM, Jim Lucas li...@cmsws.com wrote:

On 8/9/2012 5:01 PM, Al wrote:


Getting Too many open files error when processing an email batch
process.

I've looked extensively and can't find more than about 100 files that
could be open.  All my fetching is with get_file_contents();



Why not use fopen() and other related functions to open/grap/close your
batch of files?

You could replace a call like this:

$data = file_get_contents($filename);

with this:

if ( $fh = fopen($filename, 'r') ) {
   $data = fread($fh, filesize($filename));
   fclose($fh);
}

This should take care of your issue.

Jim Lucas


Why on earth would you want to reinvent the wheel? There's no point in
saying that fopen/fread/fclose is better, in fact, let me quote from
the manual page of file_get_contents:
file_get_contents() is the preferred way to read the contents of a
file into a string. It will use memory mapping techniques if supported
by your OS to enhance performance.

If your solution would fix the problem (I doubt, but ok), then you
should report a bug to the PHP devs that file_get_contents is broken.


It wouldn't fix the problem. Performing fopen/fread/fclose in PHP is 
slower than the same process implemented in C in the PHP engine. Thus 
the file will spend more time in the open state thus exacerbating the 
problem.


Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

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



Re: [PHP] Too many open files

2012-08-10 Thread Daniel Brown
On Fri, Aug 10, 2012 at 10:22 AM, Robert Cummings rob...@interjinn.com wrote:
 On 12-08-09 08:01 PM, Al wrote:
 I can't find a way to see what files could be open or what the limit is.

 Site is on a shared server, cPanel.

^
 THIS is probably your problem. Too many open files indicates that either the
 user OR the OS has reached its limit of allowed open file handles. Open
 files are those used by the OS and every user on the shared server. The
 setting can be changed but you'll need an administrator to increase the
 number of allowed open files. I suspect it's at the OS level if indeed you
 only have 100 files open (though you likely have more due to files opened
 for you by the OS or whatnot.

Rob is exactly right.  This is managed via the kernel and ulimit,
to prevent excessive resource usage.  Often it's a temporary problem,
but if it consistently occurs, your host may either be improperly
configured or, more likely, overselling resources.

-- 
/Daniel P. Brown
Network Infrastructure Manager
http://www.php.net/

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



[PHP] Too many open files

2012-08-09 Thread Al

Getting Too many open files error when processing an email batch process.

The batch size is actually rather small and the email text is small likewise.

I've looked extensively and can't find more than about 100 files that could be 
open.  All my fetching is with get_file_contents();


I can't find a way to see what files could be open or what the limit is.

Site is on a shared server, cPanel.

I've googled extensively but can't find much to help analyze the problem. Only 
solutions I can find involve having the host tech people up the file limit. I 
don't generally like this for a solution because my application is designed to 
run shared hosts.


Opinion...  Would using a cache for my main file possibly help the problem.  It 
gets called about 30 times per php page executed.


Thanks

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



Re: [PHP] Too many open files

2012-08-09 Thread Jim Lucas

On 8/9/2012 5:01 PM, Al wrote:

Getting Too many open files error when processing an email batch process.

I've looked extensively and can't find more than about 100 files that
could be open.  All my fetching is with get_file_contents();



Why not use fopen() and other related functions to open/grap/close your 
batch of files?


You could replace a call like this:

$data = file_get_contents($filename);

with this:

if ( $fh = fopen($filename, 'r') ) {
  $data = fread($fh, filesize($filename));
  fclose($fh);
}

This should take care of your issue.

Jim Lucas

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



Re: [PHP] Too many open files

2012-08-09 Thread Jim Lucas

On 8/9/2012 9:40 PM, Alan Hoffmeister wrote:

+1 to fopen and fclose.

You can implement your function:

function read($file){
   if ( $fh = fopen($file, 'r') ) {
 $data = fread($fh, filesize($file));
 fclose($fh);
   }
}

echo read('hello-world.txt');
echo read('hello-world1.txt');
echo read('hello-world2.txt');
echo read('hello-world3.txt');

This way you will close one file before start reading the other one.

--
Att,
Alan Hoffmeister


You top posted AND you didn't send it to the list...

Jim




2012/8/10 Jim Lucas li...@cmsws.com:

On 8/9/2012 5:01 PM, Al wrote:


Getting Too many open files error when processing an email batch
process.

I've looked extensively and can't find more than about 100 files that
could be open.  All my fetching is with get_file_contents();



Why not use fopen() and other related functions to open/grap/close your
batch of files?

You could replace a call like this:

$data = file_get_contents($filename);

with this:

if ( $fh = fopen($filename, 'r') ) {
   $data = fread($fh, filesize($filename));
   fclose($fh);
}

This should take care of your issue.

Jim Lucas


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




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



[PHP] Too many open files

2009-04-05 Thread Larry Garfield
I've a site on a shared host that is for the most part working well.  However, 
more recently I've started getting the following error:

failed to open stream: Too many open files in system in filename on line 
blah.

When it happens it will happen to everyone for a short period, and then stop.  
There does not seem to be much if any functionality failure when that error 
appears (I am just seeing the error in my application logs so I can't be 
sure), but it is still highly annoying and worrisome.  The number of files used 
by my application has not changed in months, however.

I know PHP has a max-files-open limit somewhere.  Is that per process, per 
user, or per server?  Is this even something I can address myself in my app, 
or does it indicate that the server itself is getting over-busy and I have to 
just beg my web host for a less busy server?  Any other thoughts as to how to 
respond?

Cheers.

-- 
Larry Garfield
la...@garfieldtech.com

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



Re: [PHP] Too many open files

2009-04-05 Thread Daniel Brown
On Sun, Apr 5, 2009 at 12:57, Larry Garfield la...@garfieldtech.com wrote:

 I know PHP has a max-files-open limit somewhere.  Is that per process, per
 user, or per server?  Is this even something I can address myself in my app,
 or does it indicate that the server itself is getting over-busy and I have to
 just beg my web host for a less busy server?  Any other thoughts as to how to
 respond?

Is your PHP suExec'd through Apache?

Also, you (or, since you're on a shared server, your admin) should
check the output from `ulimit -a`.  Most likely, it's set too low
(perhaps to the default 256) and someone else on the server is opening
multiple files simultaneously, an influx in customers is collectively
exceeding the limit, or someone's not closing their file handles.

In such a case, the admin should edit /etc/system and up the
limits on 'rlim_fd_cur' and 'rlim_fd_max.'  Just warn them to watch
what numbers they use, and not to go over 1024.  This is kernel
tuning, so once the changes have been made, the server needs to reboot
(power cycle, not an Apache reload) for them to take effect.

-- 
/Daniel P. Brown
daniel.br...@parasane.net || danbr...@php.net
http://www.parasane.net/ || http://www.pilotpig.net/
50% Off All Shared Hosting Plans at PilotPig: Use Coupon DOW1

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



[PHP] Too many open files

2003-01-10 Thread Macrosoft
Can anybody explain me what does mean error:

Warning: main(footer.inc.php) [function.main.html]: failed to
create stream:
Too many open files in /www/sql/main.php on line 96

(phpPgAdmin 2.4.2 scripts, PHP 4.3.0 + Apache)

Does PHP exceed any limit of opened files? How can I change the limit?

Krzysztof Czuma
[EMAIL PROTECTED]



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




Re: [PHP] Too many open files

2003-01-10 Thread Rus Foster
On Wed, 8 Jan 2003, Macrosoft wrote:

 Can anybody explain me what does mean error:

 Warning: main(footer.inc.php) [function.main.html]: failed to
 create stream:
 Too many open files in /www/sql/main.php on line 96

 (phpPgAdmin 2.4.2 scripts, PHP 4.3.0 + Apache)

 Does PHP exceed any limit of opened files? How can I change the limit?

 Krzysztof Czuma
 [EMAIL PROTECTED]



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

That looks more like a operating system limit. Can you check the SYSLOG on
the host at all?

Rgds

Rus
--
http://www.fsck.me.uk - My blog
http://www.65535.net - $120 for a lifetime UNIX shell account


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




Re: [PHP] Too many open files

2003-01-10 Thread Michael Sims
On Fri, 10 Jan 2003 10:38:31 + (GMT), you wrote:

On Wed, 8 Jan 2003, Macrosoft wrote:

 Can anybody explain me what does mean error:

 Warning: main(footer.inc.php) [function.main.html]: failed to
 create stream:
 Too many open files in /www/sql/main.php on line 96

 (phpPgAdmin 2.4.2 scripts, PHP 4.3.0 + Apache)

 Does PHP exceed any limit of opened files? How can I change the limit?

As someone else said, this is an OS issue, but if you're running on
Linux do a Google search for:

/proc/sys/fs/file-max

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




Re: [PHP] Too many open files

2003-01-10 Thread Gerald Timothy Quimpo
On Friday 10 January 2003 09:27 pm, Michael Sims wrote:
  Warning: main(footer.inc.php) [function.main.html]: failed
  to create stream:
  Too many open files in /www/sql/main.php on line 96

 As someone else said, this is an OS issue, but if you're running on
 Linux do a Google search for:

 /proc/sys/fs/file-max

something else to point out.  if you are hitting this limit, it's possible
that you're doing something wrong.  what does main.php do?  how
many files does it include?  what are you trying to do in there that
could lead to opening lots of files?  e.g., do you have a loop that
opens files, does something with them, then continues the loop
(opening more files without closing the previously opened files
that you don't need anymore)?

tiger

-- 
Gerald Timothy Quimpo  tiger*quimpo*org gquimpo*sni-inc.com tiger*sni*ph
Public Key: gpg --keyserver pgp.mit.edu --recv-keys 672F4C78
   Veritas liberabit vos.
   Doveryai no proveryai.

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