php-general Digest 28 Jun 2011 03:07:49 -0000 Issue 7379

Topics (messages 313755 through 313770):

Re: Php filter validate url
        313755 by: Shawn McKenzie
        313756 by: Plamen Ivanov
        313757 by: Jim Lucas
        313760 by: Plamen Ivanov

How to implement Authentication of UNIX users?
        313758 by: With No Name
        313759 by: vikash.iitb.gmail.com
        313761 by: With No Name
        313763 by: Stuart Dallas

Benchmark two functions against each other?
        313762 by: Scott Baker
        313766 by: Stuart Dallas
        313767 by: Scott Baker
        313768 by: Stuart Dallas

PHP as  CGI-CLI on FreeBSD/Apache22
        313764 by: Grant Peel
        313765 by: Nilesh Govindarajan

help for memcached Segmentation fault
        313769 by: xucheng
        313770 by: xucheng

Administrivia:

To subscribe to the digest, e-mail:
        [email protected]

To unsubscribe from the digest, e-mail:
        [email protected]

To post to the list, e-mail:
        [email protected]


----------------------------------------------------------------------
--- Begin Message ---
On 06/27/2011 10:01 AM, Plamen Ivanov wrote:
> On Sun, Jun 26, 2011 at 5:44 PM, Shawn McKenzie <[email protected]> wrote:
>>
>> On 06/26/2011 12:31 PM, Adam Tong wrote:
>>> Hi,
>>>
>>> I wanted tu use php filters for validation to avoid regular expresions.
>>> Is it possible that FILTER_VALIDATE_URL only checks if the string has
>>> http:// and do not check for the format domain.something?
>>> ----
>>> $url = 'http://wwwtestcom';
>>> $url = filter_var($url,FILTER_VALIDATE_URL);
>>> echo $url;
>>> -----
>>>
>>> Or I am doing something wrong
>>>
>>> Thank you
>>
>> Unless I'm totally misunderstanding what you want (validate that a
>> string starts with http://) try:
>>
>> if(strpos($url, 'http://') === 0) {
>>   //starts with http://
>> } esle {
>>   // does not start with http://
>> }
>>
>> --
>> Thanks!
>> -Shawn
>> http://www.spidean.com
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
> 
> Another possible solution could be:
> 
> $ary = explode('://', $url);
> if (1 >= count($ary)) {
>     echo 'No schema specified!';
> } else {
>     // Schema specified.
>     // $ary[0] is the protocol
>     $allowed = array('http', 'https');
>     if (FALSE == in_array($ary[0], $allowed) {
>         // Protocol not valid!
>         exit(1); // or return FALSE; whatever...
>     }
>     // $ary[1] is the uri, validate with filter_var().
> }
> 
> Hope this helps.

May make more sense to use parse_url() than explode.

-- 
Thanks!
-Shawn
http://www.spidean.com

--- End Message ---
--- Begin Message ---
On Mon, Jun 27, 2011 at 11:14 AM, Shawn McKenzie <[email protected]> wrote:
> On 06/27/2011 10:01 AM, Plamen Ivanov wrote:
>> On Sun, Jun 26, 2011 at 5:44 PM, Shawn McKenzie <[email protected]> wrote:
>>>
>>> On 06/26/2011 12:31 PM, Adam Tong wrote:
>>>> Hi,
>>>>
>>>> I wanted tu use php filters for validation to avoid regular expresions.
>>>> Is it possible that FILTER_VALIDATE_URL only checks if the string has
>>>> http:// and do not check for the format domain.something?
>>>> ----
>>>> $url = 'http://wwwtestcom';
>>>> $url = filter_var($url,FILTER_VALIDATE_URL);
>>>> echo $url;
>>>> -----
>>>>
>>>> Or I am doing something wrong
>>>>
>>>> Thank you
>>>
>>> Unless I'm totally misunderstanding what you want (validate that a
>>> string starts with http://) try:
>>>
>>> if(strpos($url, 'http://') === 0) {
>>>   //starts with http://
>>> } esle {
>>>   // does not start with http://
>>> }
>>>
>>> --
>>> Thanks!
>>> -Shawn
>>> http://www.spidean.com
>>>
>>> --
>>> PHP General Mailing List (http://www.php.net/)
>>> To unsubscribe, visit: http://www.php.net/unsub.php
>>>
>>
>> Another possible solution could be:
>>
>> $ary = explode('://', $url);
>> if (1 >= count($ary)) {
>>     echo 'No schema specified!';
>> } else {
>>     // Schema specified.
>>     // $ary[0] is the protocol
>>     $allowed = array('http', 'https');
>>     if (FALSE == in_array($ary[0], $allowed) {
>>         // Protocol not valid!
>>         exit(1); // or return FALSE; whatever...
>>     }
>>     // $ary[1] is the uri, validate with filter_var().
>> }
>>
>> Hope this helps.
>
> May make more sense to use parse_url() than explode.
>
> --
> Thanks!
> -Shawn
> http://www.spidean.com
>

http://php.net/manual/en/function.parse-url.php
"This function is not meant to validate the given URL..."

I would use parse_url() after URL validation.

--- End Message ---
--- Begin Message ---
On 6/27/2011 8:25 AM, Plamen Ivanov wrote:
> On Mon, Jun 27, 2011 at 11:14 AM, Shawn McKenzie <[email protected]> wrote:
>> On 06/27/2011 10:01 AM, Plamen Ivanov wrote:
>>> On Sun, Jun 26, 2011 at 5:44 PM, Shawn McKenzie <[email protected]> 
>>> wrote:
>>>>
>>>> On 06/26/2011 12:31 PM, Adam Tong wrote:
>>>>> Hi,
>>>>>
>>>>> I wanted tu use php filters for validation to avoid regular expresions.
>>>>> Is it possible that FILTER_VALIDATE_URL only checks if the string has
>>>>> http:// and do not check for the format domain.something?
>>>>> ----
>>>>> $url = 'http://wwwtestcom';
>>>>> $url = filter_var($url,FILTER_VALIDATE_URL);
>>>>> echo $url;
>>>>> -----
>>>>>
>>>>> Or I am doing something wrong
>>>>>
>>>>> Thank you
>>>>
>>>> Unless I'm totally misunderstanding what you want (validate that a
>>>> string starts with http://) try:
>>>>
>>>> if(strpos($url, 'http://') === 0) {
>>>>   //starts with http://
>>>> } esle {
>>>>   // does not start with http://
>>>> }
>>>>
>>>> --
>>>> Thanks!
>>>> -Shawn
>>>> http://www.spidean.com
>>>>
>>>> --
>>>> PHP General Mailing List (http://www.php.net/)
>>>> To unsubscribe, visit: http://www.php.net/unsub.php
>>>>
>>>
>>> Another possible solution could be:
>>>
>>> $ary = explode('://', $url);
>>> if (1 >= count($ary)) {
>>>     echo 'No schema specified!';
>>> } else {
>>>     // Schema specified.
>>>     // $ary[0] is the protocol
>>>     $allowed = array('http', 'https');
>>>     if (FALSE == in_array($ary[0], $allowed) {
>>>         // Protocol not valid!
>>>         exit(1); // or return FALSE; whatever...
>>>     }
>>>     // $ary[1] is the uri, validate with filter_var().
>>> }
>>>
>>> Hope this helps.
>>
>> May make more sense to use parse_url() than explode.
>>
>> --
>> Thanks!
>> -Shawn
>> http://www.spidean.com
>>
> 
> http://php.net/manual/en/function.parse-url.php
> "This function is not meant to validate the given URL..."
> 
> I would use parse_url() after URL validation.
> 

Shawn meant to use parse_url() in place of your explode statement.  He didn't
say to use parse_url() as a method to validate the url.

He said it would make more sense to do the following.

Also, use strict type matching if you want to compare against boolean(FALSE)

$allowed = array('http', 'https');

$scheme = parse_url($url, PHP_URL_SCHEME);

if (FALSE === in_array($scheme, $allowed) {
  // Protocol not valid!
  exit(1); // or return FALSE; whatever...
}

Seems a little less muddy to me.

Jim Lucas

--- End Message ---
--- Begin Message ---
On Mon, Jun 27, 2011 at 11:34 AM, Jim Lucas <[email protected]> wrote:
> On 6/27/2011 8:25 AM, Plamen Ivanov wrote:
>> On Mon, Jun 27, 2011 at 11:14 AM, Shawn McKenzie <[email protected]> 
>> wrote:
>>> On 06/27/2011 10:01 AM, Plamen Ivanov wrote:
>>>> On Sun, Jun 26, 2011 at 5:44 PM, Shawn McKenzie <[email protected]> 
>>>> wrote:
>>>>>
>>>>> On 06/26/2011 12:31 PM, Adam Tong wrote:
>>>>>> Hi,
>>>>>>
>>>>>> I wanted tu use php filters for validation to avoid regular expresions.
>>>>>> Is it possible that FILTER_VALIDATE_URL only checks if the string has
>>>>>> http:// and do not check for the format domain.something?
>>>>>> ----
>>>>>> $url = 'http://wwwtestcom';
>>>>>> $url = filter_var($url,FILTER_VALIDATE_URL);
>>>>>> echo $url;
>>>>>> -----
>>>>>>
>>>>>> Or I am doing something wrong
>>>>>>
>>>>>> Thank you
>>>>>
>>>>> Unless I'm totally misunderstanding what you want (validate that a
>>>>> string starts with http://) try:
>>>>>
>>>>> if(strpos($url, 'http://') === 0) {
>>>>>   //starts with http://
>>>>> } esle {
>>>>>   // does not start with http://
>>>>> }
>>>>>
>>>>> --
>>>>> Thanks!
>>>>> -Shawn
>>>>> http://www.spidean.com
>>>>>
>>>>> --
>>>>> PHP General Mailing List (http://www.php.net/)
>>>>> To unsubscribe, visit: http://www.php.net/unsub.php
>>>>>
>>>>
>>>> Another possible solution could be:
>>>>
>>>> $ary = explode('://', $url);
>>>> if (1 >= count($ary)) {
>>>>     echo 'No schema specified!';
>>>> } else {
>>>>     // Schema specified.
>>>>     // $ary[0] is the protocol
>>>>     $allowed = array('http', 'https');
>>>>     if (FALSE == in_array($ary[0], $allowed) {
>>>>         // Protocol not valid!
>>>>         exit(1); // or return FALSE; whatever...
>>>>     }
>>>>     // $ary[1] is the uri, validate with filter_var().
>>>> }
>>>>
>>>> Hope this helps.
>>>
>>> May make more sense to use parse_url() than explode.
>>>
>>> --
>>> Thanks!
>>> -Shawn
>>> http://www.spidean.com
>>>
>>
>> http://php.net/manual/en/function.parse-url.php
>> "This function is not meant to validate the given URL..."
>>
>> I would use parse_url() after URL validation.
>>
>
> Shawn meant to use parse_url() in place of your explode statement.  He didn't
> say to use parse_url() as a method to validate the url.
>
> He said it would make more sense to do the following.
>
> Also, use strict type matching if you want to compare against boolean(FALSE)
>
> $allowed = array('http', 'https');
>
> $scheme = parse_url($url, PHP_URL_SCHEME);
>
> if (FALSE === in_array($scheme, $allowed) {
>  // Protocol not valid!
>  exit(1); // or return FALSE; whatever...
> }
>
> Seems a little less muddy to me.
>
> Jim Lucas
>

Makes sense now.

Thanks guys.

--- End Message ---
--- Begin Message ---
Hello,

I try to code a Webinterface to access my Server @home which has a
couple of UNIX users.

However, I like to have only one website where users must go to whatch
the content of there Folders, which mean, I need a maping which is not
the problem but how must I make the Login/Passwd process, that I get
the right users ${HOME} and can work on it?

I have found one suggestion in the php-general archive, but this is a
very huge monster I do not want to use (>40 MByte only to authentcate?)

Thanks


--- End Message ---
--- Begin Message ---
This may help: http://php.net/manual/en/book.ssh2.php

Thanks,
Vikash Kumar
--
http://vika.sh


On 27 June 2011 21:07, With No Name <[email protected]> wrote:

> Hello,
>
> I try to code a Webinterface to access my Server @home which has a
> couple of UNIX users.
>
> However, I like to have only one website where users must go to whatch
> the content of there Folders, which mean, I need a maping which is not
> the problem but how must I make the Login/Passwd process, that I get
> the right users ${HOME} and can work on it?
>
> I have found one suggestion in the php-general archive, but this is a
> very huge monster I do not want to use (>40 MByte only to authentcate?)
>
> Thanks
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--- End Message ---
--- Begin Message ---
On Mon, June 27, 2011 5:41 pm, [email protected] wrote:
> This may help: http://php.net/manual/en/book.ssh2.php

Unfortunately not, I have only one server on my DSL and using
ssh on the same host has a poor performance.  I have tried it
already and each download or directory change takes ages...

SSH need arround 2-7 seconds to respond to a new connect.

Thanks


--- End Message ---
--- Begin Message ---
On Mon, Jun 27, 2011 at 5:27 PM, With No Name <[email protected]> wrote:

> SSH need arround 2-7 seconds to respond to a new connect.
>

Not PHP-related, but you might want to try adding "UseDNS no" to your
sshd_config file on the server. SSH connection delays are commonly caused by
SSHd doing an rDNS lookup for a non-existant record. Turn that off and you
might see an improvement in connect speed.

-Stuart

-- 
Stuart Dallas
3ft9 Ltd
http://3ft9.com/

--- End Message ---
--- Begin Message ---
I have functions that I'd like to benchmark and compare. What are the
best PHP libraries or websites to do that? Something like jsperf.com but
for PHP would be ideal.

- Scott

--- End Message ---
--- Begin Message ---
On Mon, Jun 27, 2011 at 5:34 PM, Scott Baker <[email protected]> wrote:

> I have functions that I'd like to benchmark and compare. What are the
> best PHP libraries or websites to do that? Something like jsperf.com but
> for PHP would be ideal.
>

You're not going to find a service that will let you do that - allowing
arbitrary PHP to be entered into a website to be executed is far too
dangerous.

Just knocked this up, should do what you want:
https://gist.github.com/1049335

-Stuart

-- 
Stuart Dallas
3ft9 Ltd
http://3ft9.com/

--- End Message ---
--- Begin Message ---
On 06/27/2011 10:33 AM, Stuart Dallas wrote:
> 
> You're not going to find a service that will let you do that - allowing
> arbitrary PHP to be entered into a website to be executed is far too
> dangerous.

I would have thought so too but I found these:

http://codepad.viper-7.com/
http://codepad.org/
http://ideone.com/

> Just knocked this up, should do what you
> want:Â https://gist.github.com/1049335

Thanks I'll check it out!

-- 
Scott Baker - Canby Telcom
System Administrator - RHCE - 503.266.8253

--- End Message ---
--- Begin Message ---
On Mon, Jun 27, 2011 at 6:39 PM, Scott Baker <[email protected]> wrote:

> On 06/27/2011 10:33 AM, Stuart Dallas wrote:
> >
> > You're not going to find a service that will let you do that - allowing
> > arbitrary PHP to be entered into a website to be executed is far too
> > dangerous.
>
> I would have thought so too but I found these:
>
> http://codepad.viper-7.com/
> http://codepad.org/
> http://ideone.com/


That's surprising, but reading around those sites a little it seems they're
running the code in isolated virtual machines which are firewalled to
prevent outgoing network connections. Very nice!

-Stuart

-- 
Stuart Dallas
3ft9 Ltd
http://3ft9.com/

--- End Message ---
--- Begin Message ---
Hi all,

Up to this point we have been running PHP as an Apache 22 module.

We would like to rebuild PHP over the next few weeks to run it as a CGI/CLI 
PHPSuexec system.

I am hoping there may be others that have made this migration and might have a 
step by step how to (so far research shows it should be reasonably simple to 
do), and would be willing to share it.

Right now we have 

FreeBSD 8.0
Apache22 built from ports, with apache suexec enabled,
PHP5 Built from ports,

Any hints are appreciated,

-G

--- End Message ---
--- Begin Message ---
On 06/27/2011 10:13 PM, Grant Peel wrote:
> Hi all,
>
> Up to this point we have been running PHP as an Apache 22 module.
>
> We would like to rebuild PHP over the next few weeks to run it as a CGI/CLI 
> PHPSuexec system.
>
> I am hoping there may be others that have made this migration and might have 
> a step by step how to (so far research shows it should be reasonably simple 
> to do), and would be willing to share it.
>
> Right now we have 
>
> FreeBSD 8.0
> Apache22 built from ports, with apache suexec enabled,
> PHP5 Built from ports,
>
> Any hints are appreciated,
>
> -G

PHP in CGI sucks at performance, you should give a thought to fastcgi +
php + suexec as in here: http://forum.linode.com/viewtopic.php?t=2982
Though its written for ubuntu, you can derive some tricks from there.
I don't know if php-fpm + suexec is possible. php-fpm is best for fastcgi.

-- 
Regards,
Nilesh Govindarajan
@nileshgr


--- End Message ---
--- Begin Message ---
Hi all,
       I wrap pecl-memcache into a class used as a sigleton class .
the code is :
==================================================code===================================================================================
       class Mem{

        private static $_instance = null ;//singlton object instance

        private function __construct(){

                        global $config ;
                        $servers = $config['memcached'] ;
                        $mem = new Memcache ;
                        foreach($servers as $server){
                                $mem->addServer($server['host'],
$server['port'], intval($server['persistent']) > 0 ? 1 : 0,
intval($server['weight']) > 0 ? intval($server['weight']) : 1 ) ;
                        }
                        return $mem ;

        }

        private static function getInstance(){

                        if(self::$_instance === null || !(
self::$_instance instanceof Mem ) ){

                                        self::$_instance = new Mem() ;

                        }

                        return true ;

        }

        public static function get($key){

                        self::getInstance() ;
                        return self::$_instance->get(md5(strtolower($key))) ;

        }

        public static function set($key, $value, $ttl=0){
                        self::getInstance() ;
                        $compress = (is_bool($value) || is_int($value)
|| is_float($value)) ? false : MEMCACHE_COMPRESSED ;
                        return
self::$_instance->set(md5(strtolower($key)), $value, $compress, $ttl)
;

        }

        public static function rm($key){
                        self::getInstance() ;
                        return
self::$_instance->delete(md5(strtolower($key)),0) ;
        }
}

===============================================================code==========================================================

and $config['memcached'] is an array contains info about the server .
$config['memcached'] = array('host'=>'localhost', port=11211,
persistent=1,weight=1) ;

when i run this , i got "Segmentation fault" ! I cannot figure out
what's the problem . any commet appreciate .

and i used memcached 1.4.5 , and libevent-1.4.13-1
php 5.2.16

--- End Message ---
--- Begin Message ---
sorry, the right $config['memcached'] variable is

$config['memcached']=array(array('host'=>'localhost', port=11211,
persistent=1,weight=1));

2011/6/28 xucheng <[email protected]>:
> Hi all,
>       I wrap pecl-memcache into a class used as a sigleton class .
> the code is :
> ==================================================code===================================================================================
>       class Mem{
>
>        private static $_instance = null ;//singlton object instance
>
>        private function __construct(){
>
>                        global $config ;
>                        $servers = $config['memcached'] ;
>                        $mem = new Memcache ;
>                        foreach($servers as $server){
>                                $mem->addServer($server['host'],
> $server['port'], intval($server['persistent']) > 0 ? 1 : 0,
> intval($server['weight']) > 0 ? intval($server['weight']) : 1 ) ;
>                        }
>                        return $mem ;
>
>        }
>
>        private static function getInstance(){
>
>                        if(self::$_instance === null || !(
> self::$_instance instanceof Mem ) ){
>
>                                        self::$_instance = new Mem() ;
>
>                        }
>
>                        return true ;
>
>        }
>
>        public static function get($key){
>
>                        self::getInstance() ;
>                        return self::$_instance->get(md5(strtolower($key))) ;
>
>        }
>
>        public static function set($key, $value, $ttl=0){
>                        self::getInstance() ;
>                        $compress = (is_bool($value) || is_int($value)
> || is_float($value)) ? false : MEMCACHE_COMPRESSED ;
>                        return
> self::$_instance->set(md5(strtolower($key)), $value, $compress, $ttl)
> ;
>
>        }
>
>        public static function rm($key){
>                        self::getInstance() ;
>                        return
> self::$_instance->delete(md5(strtolower($key)),0) ;
>        }
> }
>
> ===============================================================code==========================================================
>
> and $config['memcached'] is an array contains info about the server .
> $config['memcached'] = array('host'=>'localhost', port=11211,
> persistent=1,weight=1) ;
>
> when i run this , i got "Segmentation fault" ! I cannot figure out
> what's the problem . any commet appreciate .
>
> and i used memcached 1.4.5 , and libevent-1.4.13-1
> php 5.2.16
>

--- End Message ---

Reply via email to