php-general Digest 10 Aug 2012 14:22:36 -0000 Issue 7917

Topics (messages 318660 through 318666):

Re: PHP session variables
        318660 by: Jim Lucas

Re: XML/PHP web service
        318661 by: Carlos Medina

Too many open files
        318662 by: Al
        318663 by: Jim Lucas
        318664 by: Jim Lucas
        318665 by: Matijn Woudt
        318666 by: Robert Cummings

Administrivia:

To subscribe to the digest, e-mail:
        php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
        php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
        php-gene...@lists.php.net


----------------------------------------------------------------------
--- Begin Message ---
On 08/09/2012 01:45 PM, Tedd Sperling wrote:
On Aug 8, 2012, at 5:41 PM, Jim Giner<jim.gi...@albanyhandball.com>  wrote:

On 8/8/2012 11:24 AM, Ansry User 01 wrote:
I am setting the _SESSION variables in one of my file, but whenever I leave the 
php page session variables are not accessible. Not sure what I need to do 
additionally other then defining _SESSION[].
Any pointer.

You must make it a habit to start each script with

session_start();


I like this way:

if (!session_id())
        {
        session_start();
        }

Cheers,

tedd

_____________________
t...@sperling.com
http://sperling.com



You are relying on PHP's loose typing.  This is a poor check.

session_id() returns a string, not boolean.

You should do this instead.

if ( session_id() === '' )
....


--
Jim Lucas

http://www.cmsws.com/
http://www.cmsws.com/examples/

--- End Message ---
--- Begin Message ---
Hi,
the two options offers here are ok. But please make it secure!

Regards

Carlos

Am 09.08.2012 14:38, schrieb Alejandro Michelin Salomon:
> Philip :
> 
> Try this:
> 
> Client:
> 
> $client = new SoapClient( null, array( 'encoding' => 'utf-8', 'soap_version'
> => SOAP_1_2, 'trace' => 1, 
>                                  'uri' => 'tns: Server', 'location' => 'php
> server URL here'));
> 
> // Cut off <?xml version="1.0" encoding="utf-8"?>, to not have two xml start
> tag in the soap message.
> $xmlres = $client->__soapCall( 'ProXML', array( str_replace( '<?xml
> version="1.0" encoding="utf-8"?>'."\n", '', $sXml )));
> 
> echo '<pre>', $xmlres, '</pre>'; // print the xml output or
> var_export($xmlres, true) if $xmlres is an array.
> 
> 
> SERVER:
> 
> 
> class Receiver
> {
>     public function ProXML ( $sXML )
>     {
> 
>         libxml_use_internal_errors(true); // enabled use libxml errors
> 
>         // try..catch to cacth simplexmlelement errors
>         try
>         {
>             $xml = new SimpleXMLElement( '<?xml version="1.0"
> encoding="utf-8"?>' . $sXML ); // Try to create a xml object with the string
> passed
>         } catch (Exception $e) {
>             
>             $aErrors = libxml_get_errors(); // get errors
> 
>                       foreach ( $aErros as $oErro )
>                     {
>                     switch ( $oErro->level )
>                     {
>                         case LIBXML_ERR_WARNING:
>                             $sCod .= '<return><code>' . $oErro->code .
> '</code><menssage>' . utf8_encode( 'warning: ' . $oErro->message ) .
>                                     '</menssage></return>';
>                     break;
>                 case LIBXML_ERR_ERROR:
>                     $sCod .= '<resposta><codigo>' . $oErro->code .
> '</code><menssage>' . utf8_encode( 'Error: ' . $oErro->message ) .
>                              '</menssage></return>';
>                     break;
>                  case LIBXML_ERR_FATAL:
>                     $sCod .= '<resposta><codigo>' . $oErro->code .
> '</code><menssage>' . utf8_encode( ' Fatal Error: ' . $oErro->message ) .
>                              '</menssage></return>';
>                      break;
>                     }
>                  }
>         }
> 
>         work here ...
> 
>     }
> 
> }
> 
> 
> $server = new SoapServer(null, array( 'uri' => 'tns: Server' ));
> 
> $server->setClass('Receiver');
> 
> $server->handle();
> 
> 
> 
> 
> Alejandro M.S
> 
> -----Mensagem original-----
> De: Phillip Baker [mailto:phil...@freewolf.net] 
> Enviada em: quarta-feira, 8 de agosto de 2012 19:12
> Para: php-gene...@lists.php.net
> Assunto: [PHP] XML/PHP web service
> 
> Greetings all,
> 
> I am looking for some options here.
> 
> I am in need of creating a service on our web server that will always be
> available and automated.
> It will accept an XML file.
> 
> I will be checking to see if the XML file is valid and then passing it on to
> another server.
> But I need to accept this file without using a submit form.
> I have never done anything like this and looking for ideas.
> 
> I am using a lamp environment and looking for suggestions.
> 
> I am looking to set this up so that our vendors can set up scripts to
> automatically post XML files to our servers.
> 
> Blessed Be
> 
> Phillip
> 
> "In the Jim Crow South, for example, government failed and indeed refused to
> protect blacks from extra-legal violence. Given our history, it's stunning
> we fail to question those who would force upon us a total reliance on the
> state for defense."
> -- Robert J. Cottrol
> 


--- End Message ---
--- Begin Message ---
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....

--- End Message ---
--- Begin Message ---
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

--- End Message ---
--- Begin Message ---
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



--- End Message ---
--- Begin Message ---
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

--- End Message ---
--- Begin Message ---
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.

--- End Message ---

Reply via email to