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

2012-08-10 Thread php-general-digest-help

php-general Digest 10 Aug 2012 14:22:36 - 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


--
---BeginMessage---

On 08/09/2012 01:45 PM, Tedd Sperling wrote:

On Aug 8, 2012, at 5:41 PM, Jim Ginerjim.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---
---BeginMessage---
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 .= 'returncode' . $oErro-code .
 '/codemenssage' . utf8_encode( 'warning: ' . $oErro-message ) .
 '/menssage/return';
 break;
 case LIBXML_ERR_ERROR:
 $sCod .= 'respostacodigo' . $oErro-code .
 '/codemenssage' . utf8_encode( 'Error: ' . $oErro-message ) .
  '/menssage/return';
 break;
  case LIBXML_ERR_FATAL:
 $sCod .= 'respostacodigo' . $oErro-code .
 '/codemenssage' . 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 

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] PHP session variables

2012-08-10 Thread Tedd Sperling
On Aug 9, 2012, at 5:16 PM, Jim Lucas li...@cmsws.com wrote:
 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

Thanks Jim -- you're right.

What about?

if (!defined(SID))
{
session_start();
}


Cheers,

tedd

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


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



Re: [PHP] PHP session variables

2012-08-10 Thread Tedd Sperling
On Aug 10, 2012, at 11:45 AM, Tedd Sperling t...@sperling.com wrote:

 On Aug 9, 2012, at 5:16 PM, Jim Lucas li...@cmsws.com wrote:
 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
 
 Thanks Jim -- you're right.
 
 What about?
 
 if (!defined(SID))
   {
   session_start();
   }

Before you answer, the (!defined(SID)) is over 50 times slower than ( 
session_id() === '' )

Your way is better.

Cheers,

tedd

_
t...@sperling.com
http://sperling.com
--
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