php-general Digest 13 Aug 2012 19:09:34 -0000 Issue 7920

Topics (messages 318679 through 318686):

Re: Is PHP unsuitable for HTML5 WebSockets?
        318679 by: Matijn Woudt
        318680 by: Adam Richardson

Re: How to best set per-site PHP session storage under suPHP/WordPress?
        318681 by: Ian

Re: Repeated New Object Requests
        318682 by: Robert Cummings

Re: PHP session variables
        318683 by: Robert Cummings

Re: Reading class variable value always returns NULL
        318684 by: Robert Cummings
        318685 by: Volmar Machado

Re: [PHP-WEBMASTER] php error
        318686 by: Daniel Brown

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 Mon, Aug 13, 2012 at 9:01 AM, Jim Lucas <li...@cmsws.com> wrote:
> On 8/12/2012 12:06 PM, BRIAN M. FITZPATRICK wrote:
>>
>> I've looked all over the net and I have been unable to find a concrete
>> answer to this question. I am about to start development on a web
>> application that will need to provide real-time updates of data to user's
>> browsers. WebSockets are ideal for this task.
>>
>> I have read in some places on the net that PHP is not suitable for
>> WebSockets due to it's nature. That WebSockets are designed for long running
>> threads/processes which each maintain multiple event-driven connections,
>> whereas PHP was designed around the short-lived single process procedural
>> paradigm.
>>
>> Yet on the other hand I see lots of guides and libraries (such as
>> http://socketo.me/) on the net that deal with PHP WebSockets. So I don't
>> know what to think at this stage. Is PHP a suitable platform for developing
>> a web application that requires WebSockets?
>>
>
>
> Back in 2007, I wrote a cli php script to run as a socket server for a game
> I was playing at the time.  It has been running on every server I've put
> together since then.  To say that PHP isn't suited to this type of service
> is wrong.
>
> Give it a shot.  Can't hurt to try.
>
> Jim
>

It works fine. There are many socket applications based on PHP. Just
make sure to set the time limit [1] to 0, or your script will halt.

- Matijn

[1] http://www.php.net/set_time_limit

--- End Message ---
--- Begin Message ---
> I have read in some places on the net that PHP is not suitable for WebSockets 
> due to it's nature. That WebSockets are designed for long running 
> threads/processes which each maintain multiple event-driven connections, 
> whereas PHP was designed around the short-lived single process procedural 
> paradigm.

Well, you could certainly run into trouble if you're not careful. For
example, using an Apache module PHP installation would not likely end
nicely :)

> Yet on the other hand I see lots of guides and libraries (such as 
> http://socketo.me/) on the net that deal with PHP WebSockets. So I don't know 
> what to think at this stage. Is PHP a suitable platform for developing a web 
> application that requires WebSockets?

I'm sure you could get get your application running with PHP. That
said, I personally would not use PHP for the web socket implementation
in my stack. I'd probably use Go, node.js or even Erlang for the web
socket server itself (non-blocking IO is baked into these
environments, which is handy for limiting the resources required for
this type of application), but I'd likely use PHP for components that
weren't directly tied to the web sockets (db frontend, etc.)

Obviously, that's just my personal preference, and as you've noted,
people are doing nice things in the web sockets world with PHP, so it
can be done. That said, I suspect I'd have an easier time with one of
the other languages for this particular aspect of an application, as
the resource management should be much easier to manage. I don't think
there's a "right" tool for the job, but I do believe some language
environments may better facilitate this specific type of development.

Have fun!

Adam

-- 
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com

--- End Message ---
--- Begin Message ---
On 13/08/2012 06:01, Philip Amadeo Saeli wrote:
> I'm administering WordPress sites under suPHP on a CentOS LAMP server
> and would like to know how I can set PHP to keep the session files under
> the WP user's dir without having do duplicate the entire php.ini file
> for each WP site while still maintaining adequate security.  The
> problems I'm encountering are that, AFAICT, I have basically two
> choices:
> 
>  1. Use the suPHP "suPHP_ConfigPath" to set the path to a
>     per-site php.ini file containing a "session.save_path"
>     directive.
> 
>  2. Put php.ini files with the "session.save_path" directive
>     within the WP dir hier.
> 
> The problems with the above two options (I have found no other options
> so far) are that, for the former, the system php.ini file is not read so
> the per-site php.ini file(s) have to duplicate most if not all of what's
> in the system php.ini file; this is for each WP site (if not a WP Net
> (AKA WPMU) install); and for the latter, -any-and-every- subdir in the
> WP dir hier that has code that may reference the PHP session must have
> its own php.ini file in it.  Either way it becomes a significant
> maintenance problem, especially once there are more than one or two
> such sites.
> 
> I have not been able to find much documentation on this, either in the
> PHP site or in the various help forums.  I've searched quite extensively
> and have run some tests of my own using phpinfo.php to see how things
> are set.
> 
> I do not desire to open up file permissions to bypass this PHP settings
> issue altogether due to security concerns (though I do wish an answer
> could be so simple).
> 
> What's canonical in such a case?  If nothing, are there any other
> alternatives?  My desired solution would be to be able to put one
> php.ini (or equivalent) file per site that would contain the needed
> directive which would be merged with the settings from the system
> php.ini, overriding only the session.save_path, but, AFAICT, PHP does
> not seem to allow this.  Any other ideas?
> 
> Thanks!
> 
> --Phil
> 
> 

Hi,

You can add php.ini variables to the Apache Virtual Host section for
each site, for example:


php_admin_value session.save_path "/path/to/new/session/folder"

[http://php.net/manual/en/configuration.changes.php]


This will override the save path for each site you add it to, but all
other values will be picked up from the system default.


You must make sure the Apache user has write access to the new folder.

Regards

Ian
-- 



--- End Message ---
--- Begin Message ---
On 12-08-10 02:24 PM, Al wrote:

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.

Hi Al,

New isn't defining a class, it's a request for an instance of a defined class. Thus it will create a new instance over and over again for every time the new request is made. The equivalent to "won't let you duplicate function names" is "won't let you duplicate class names".

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 ---
--- Begin Message ---
On 12-08-10 04:42 PM, Tedd Sperling wrote:
On Aug 10, 2012, at 1:21 PM, Ege Sertçetin <sertce...@itu.edu.tr> wrote:

Hi. My question will maybe out of topic, I'm sorry.
How can you know that one way will be much slower than other one? I mean, how 
can I learn which function is faster before I test it?

Ege:

No your question is on topic.

This question should be asked on the list, so I'll present Q:A instead of 
answering privately

http://www.webbytedd.com/b/timed1/

The code is there -- if you have questions, please post them to the list.

Ted,

Please see the current signature for microtime():

    mixed microtime ([ bool $get_as_float = false ] )

The optional paramter was added in PHP 5.0.0. I think it's safe to update your habits :)

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 ---
--- Begin Message ---
On 12-08-12 08:32 AM, Reto Kaiser wrote:
Hi,

So I have this strange situation where I assign a classvariable a
value, but when I read the value it is NULL.

The class has one variable declared:
=========
class A {
         private $_cookies;
}
=========

That is a private instance variable NOT a class variable.

To declare a class variable you would do the following:

<?php

class A
{
    private static $_cookies;
}

?>

In a method of this class I assign this classvariable plus an
undeclared classvariable and a local variable the value 1:
=========
$this->_cookies = 1;
$this->_cookies2 = 1;
$cookies3 = 1;
=========

When I now read the values of those variables, the classvariables are
NULL while the local variable is 1:
=========
$logEntry .= 'cookies: ' . var_export($this->_cookies, true) . PHP_EOL;
$logEntry .= 'cookies2: ' . var_export($this->_cookies2, true) . PHP_EOL;
$logEntry .= 'cookies3: ' . var_export($cookies3, true) . PHP_EOL;
=========
cookies: NULL
cookies2: NULL
cookies3: 1
=========

But when reading the whole object, the classvariables are 1:
=========
$logEntry .= var_export($this, true) . PHP_EOL;
=========
A::__set_state(array(
    '_cookies' => 1,
    '_cookies2' => 1,
))
=========


This happens periodically on a busy webserver. It seems that when it
happens, all classvariables cannot be read anymore (return NULL).
After restarting Apache it does not happen anymore, just to happen
again after some minutes.

The system is current Debian Squeeze:
Linux: linux-image-2.6.32-5-amd64
Apache: apache2-mpm-prefork 2.2.16-6+squeeze7
PHP: PHP 5.3.3-7+squeeze13 with Suhosin-Patch (cli) (built: Jun 10
2012 07:31:32)
php -m: 
https://raw.github.com/gist/3331641/2f7e80bd03abfb728b659634d3f4bac0131f4d6a/gistfile1.txt
php -i: 
https://raw.github.com/gist/3331651/bcf6e3654bf391482627505447848de173d0bbab/gistfile1.txt

Does anyone have an idea what could cause this, or how to further debug?

I can't really speak to your specific problem (unless you're using two different instances of the class), just thought I'd clear up the difference between class variables and instance variables.

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 ---
--- Begin Message ---
It's only a hint, but You start checking if the Object Ids are the same or not.

2012/8/13 Robert Cummings <rob...@interjinn.com>:
> On 12-08-12 08:32 AM, Reto Kaiser wrote:
>>
>> Hi,
>>
>> So I have this strange situation where I assign a classvariable a
>> value, but when I read the value it is NULL.
>>
>> The class has one variable declared:
>> =========
>> class A {
>>          private $_cookies;
>> }
>> =========
>
>
> That is a private instance variable NOT a class variable.
>
> To declare a class variable you would do the following:
>
> <?php
>
> class A
> {
>     private static $_cookies;
> }
>
> ?>
>
>
>> In a method of this class I assign this classvariable plus an
>> undeclared classvariable and a local variable the value 1:
>> =========
>> $this->_cookies = 1;
>> $this->_cookies2 = 1;
>> $cookies3 = 1;
>> =========
>>
>> When I now read the values of those variables, the classvariables are
>> NULL while the local variable is 1:
>> =========
>> $logEntry .= 'cookies: ' . var_export($this->_cookies, true) . PHP_EOL;
>> $logEntry .= 'cookies2: ' . var_export($this->_cookies2, true) . PHP_EOL;
>> $logEntry .= 'cookies3: ' . var_export($cookies3, true) . PHP_EOL;
>> =========
>> cookies: NULL
>> cookies2: NULL
>> cookies3: 1
>> =========
>>
>> But when reading the whole object, the classvariables are 1:
>> =========
>> $logEntry .= var_export($this, true) . PHP_EOL;
>> =========
>> A::__set_state(array(
>>     '_cookies' => 1,
>>     '_cookies2' => 1,
>> ))
>> =========
>>
>>
>> This happens periodically on a busy webserver. It seems that when it
>> happens, all classvariables cannot be read anymore (return NULL).
>> After restarting Apache it does not happen anymore, just to happen
>> again after some minutes.
>>
>> The system is current Debian Squeeze:
>> Linux: linux-image-2.6.32-5-amd64
>> Apache: apache2-mpm-prefork 2.2.16-6+squeeze7
>> PHP: PHP 5.3.3-7+squeeze13 with Suhosin-Patch (cli) (built: Jun 10
>> 2012 07:31:32)
>> php -m:
>> https://raw.github.com/gist/3331641/2f7e80bd03abfb728b659634d3f4bac0131f4d6a/gistfile1.txt
>> php -i:
>> https://raw.github.com/gist/3331651/bcf6e3654bf391482627505447848de173d0bbab/gistfile1.txt
>>
>> Does anyone have an idea what could cause this, or how to further debug?
>
>
> I can't really speak to your specific problem (unless you're using two
> different instances of the class), just thought I'd clear up the difference
> between class variables and instance variables.
>
> 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
>

--- End Message ---
--- Begin Message ---
On Mon, Aug 13, 2012 at 2:32 PM, tomas lagro <tomas.la...@hotmail.com> wrote:
>
> Hello, my name is tomas, i'm having a problem and i've checked a lot of times 
> the script and it is not that, because in my local xampp server it works 
> correctly, the issue is that i have a form on my webpage and when you submitt 
> it, the post values are not being requested, so the query array has no values 
> and has no result because of this. Is this a php.ini mistake? what can it be 
> because its driving me crazy. Thanks for ypur time

    This email belongs on the PHP General mailing list (CC'd), Tomas,
and you should subscribe to that list at
php-general-subscr...@lists.php.net to follow the discussion and get
help with your questions.

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

--- End Message ---

Reply via email to