php-general Digest 17 May 2012 20:39:55 -0000 Issue 7815
php-general Digest 17 May 2012 20:39:55 - Issue 7815 Topics (messages 317879 through 317880): Re: Performance / AB issue? 317879 by: Lars Nielsen regexp novice 317880 by: Jim Giner 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 Fri, May 11, 2012 at 9:53 AM, Camilo Sperberg unrea...@gmail.com wrote: Sent from my iPhone 5 Beta [Confidential use only] On 11 mei 2012, at 07:09, Lars Nielsen l...@lfweb.dk wrote: On 10 mei 2012, at 23:26, Lars Nielsen wrote: Sent from my iPhone 5 Beta [Confidential use only] On 10 mei 2012, at 17:40, Matijn Woudt tijn...@gmail.com wrote: On Thu, May 10, 2012 at 9:04 AM, Lars Nielsen l...@lfweb.dk wrote: Hi there, I have apache-2.22/php 5.3.10 set up on a dedicated server but I have a strange issue. I have made a Drupal 7 site with a mysql db. If I stress-test the site with : ab -c 1 -n 150 http://sitename/ it works fine. If I stress-test the site with : ab -c 2 -n 20 http://sitename/ it kills apache. If I stress-test the site with : ab -c 50 -n 1500 http://sitename/static.html it works fine. I have set apache's errorlog to debug. But it writes nothing, either in the virtualhost or in the server-file. Can anyone give a hint about what can be wrong? What do you mean with 'kills apache', does it terminate apache or does apache hang (eg. 100% cpu), and respond normal after the stress test is over? And what is the index of your site? A php script, or..? Do you have ModRewrite redirects etc? - Matijn -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Can you visit the site normally? Try less verbosing in apache, that is pretty intensive, but as you can benchmark a static file well (with moderate high settings), i assume it is some configuration problem in drupal. Greeting. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Hi, I can visit the site normaly, but with 2-3 concurrent ab test it fails. seen from 'ps' and 'htop' it seems that both apache and mysql continues to run normaly but it doesnt respond. If i run netstat -an after the test it shows this : Active Internet connections (servers and established) Proto Recv-Q Send-Q Local Address      Foreign Address  State tcp     0    0 0.0.0.0:22        0.0.0.0:*     LISTEN tcp     0    0 127.0.0.1:25       0.0.0.0:*     LISTEN tcp     0    0 127.0.0.1:3306      0.0.0.0:*     LISTEN tcp     0    0 0.0.0.0:80        0.0.0.0:*     LISTEN tcp     1    0 x.x.x.x:80     x.x.x.x:39237  CLOSE_WAIT tcp     1    0 x.x.x.x:80     x.x.x.x:39236   CLOSE_WAIT tcp     0    0 x.x.x.x:22     x.x.x.x:47383   ESTABLISHED tcp     0    0 127.0.0.1:80       127.0.0.1:34775 ESTABLISHED tcp     1    0 x.x.x.x:80     x.x.x.x:39300   CLOSE_WAIT ESTABLISHED tcp     0    0 127.0.0.1:34775     127.0.0.1:80 ESTABLISHED tcp     0    0 x.x.x.x:80     x.x.x.x:39330   ESTABLISHED tcp6    0    0 :::22          :::* LISTEN tcp6    0    0 ::1:25          :::* LISTEN So it does seem like there should be room for new tcp connections? But if I restart apache then it works again... So I guess it is a apache/php configuration issue? -- Med venlig hilsen / Best Regards LFWeb Lars Nielsen Thorsensvej 30 4800 Nykøbing Falster Tlf: +45 20 64 85 76 email : l...@lfweb.dk www : http://www.lfweb.dk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Have you tried benchmarking a really simple php page, such as ?php echo 'hello world'; ? ? It that works, than it is definitely an issue in Drupal's configuration and not in PHP/Apache. Additionally, you could check what happens when you try to establish a session or make a database call to rule out those as well, just make really simple tests that you know wouldn't fail and run ab on them. Greetings. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Thanks! Now I have made ?php  echo Hey from PHP!; ? It runs fine from a little concurrency. But with -c 5 -n 500 it fails after 308 requests! Best Regards / Med venlig hilsen LFWeb Lars Nielsen -- PHP General Mailing List
[PHP] regexp novice
ok - finally had to come up with my own regexp - and am failing. Trying to validate an input of a time value in the format hh:mm, wherein I'll accept anything like the following: hmm hhmm h:mm hh:mm in a 12 hour format. My problem is my test is ok'ing an input of 1300. Here is my test: if (0 == preg_match(/([0][1-9]|[1][0-2]|[1-9]):[0-5][0-9]/,$t)) return true; else return false; Can someone help me correct my regexp? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: regexp novice
OOPS FORGOT to mention that I modify the string to add a colon if it is entered without one, so my regexp always expects a : to be in the middle. So in actuality - my regexp is 'passing' a value of 13:00 as legitimate, when it should not be. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] regexp novice
On Fri, May 18, 2012 at 2:37 AM, Jim Giner jim.gi...@albanyhandball.comwrote: ok - finally had to come up with my own regexp - and am failing. Trying to validate an input of a time value in the format hh:mm, wherein I'll accept anything like the following: hmm hhmm h:mm hh:mm in a 12 hour format. My problem is my test is ok'ing an input of 1300. Here is my test: if (0 == preg_match(/([0][1-9]|[1][0-2]|[1-9]):[0-5][0-9]/,$t)) return true; else return false; Can someone help me correct my regexp? I can not correct your regexp. But I must tell you that trying to tweak a regex for hours is surely **not productive**. If you got any type of text processing dont always go for regular expression. This problem can be solved just by simple string parsing. Here I have done that for you. function valid_time($time){ $m = (int) substr($time, -2); $h = (int) substr($time, 0, -2); return ($h=0 $h13 $m=0 $m60); } -- Shiplu.Mokadd.im ImgSign.com | A dynamic signature machine Innovation distinguishes between follower and leader
Re: [PHP] regexp novice
Try this: /(0?[1-9]|[12][0-9]):?[0-5][0-9]/ FYI: ? is equal to {0,1}, and [1-9] to [123456789] (and therefore [1-2] to [12]). Am 17.05.2012 22:37, schrieb Jim Giner: ok - finally had to come up with my own regexp - and am failing. Trying to validate an input of a time value in the format hh:mm, wherein I'll accept anything like the following: hmm hhmm h:mm hh:mm in a 12 hour format. My problem is my test is ok'ing an input of 1300. Here is my test: if (0 == preg_match(/([0][1-9]|[1][0-2]|[1-9]):[0-5][0-9]/,$t)) return true; else return false; Can someone help me correct my regexp? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] regexp novice
Yared Hufkens y4...@yahoo.de wrote in message news:4fb5667d.7020...@yahoo.de... Try this: /(0?[1-9]|[12][0-9]):?[0-5][0-9]/ FYI: ? is equal to {0,1}, and [1-9] to [123456789] (and therefore [1-2] to [12]). Am 17.05.2012 22:37, schrieb Jim Giner: ok - finally had to come up with my own regexp - and am failing. Trying to validate an input of a time value in the format hh:mm, wherein I'll accept anything like the following: hmm hhmm h:mm hh:mm in a 12 hour format. My problem is my test is ok'ing an input of 1300. Here is my test: if (0 == preg_match(/([0][1-9]|[1][0-2]|[1-9]):[0-5][0-9]/,$t)) return true; else return false; Can someone help me correct my regexp? Nope - that didn't work. Tested it against 1900, 1300 and 13:00 and all came thru as OK. Also - I don't understand at all the following: FYI: ? is equal to {0,1}, and [1-9] to [123456789] (and therefore [1-2] to [12]). I know (?) that [1-9] validates any digit from 1 to 9 - I was already using that. And your point about [1-2] doesn't make sense to me since I need to validate 10:00 which [1-2] in my usage would cause 10:00 to fail. And I don't know what ? means at all. FWIW - I couldn't find much in the way of tutorials on the meanings of the various chars in regexp's. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] regexp novice
FWIW - I couldn't find much in the way of tutorials on the meanings of the various chars in regexp's. this helps alot: http://www.gskinner.com/RegExr/ you can paste your pattern (needle) in the top input, and hover over each char to see what it means in grep land. Paste your haystack in the big box (input), under that, to see where all your needle will be found. -- 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
Re: [PHP] regexp novice
Thank you ! Govinda govinda.webdnat...@gmail.com wrote in message news:3e5dce87-29c1-4679-ad3a-53326435f...@gmail.com... FWIW - I couldn't find much in the way of tutorials on the meanings of the various chars in regexp's. this helps alot: http://www.gskinner.com/RegExr/ you can paste your pattern (needle) in the top input, and hover over each char to see what it means in grep land. Paste your haystack in the big box (input), under that, to see where all your needle will be found. -- 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
Re: [PHP] regexp novice
On 5/17/2012 1:57 PM, shiplu wrote: On Fri, May 18, 2012 at 2:37 AM, Jim Ginerjim.gi...@albanyhandball.comwrote: ok - finally had to come up with my own regexp - and am failing. Trying to validate an input of a time value in the format hh:mm, wherein I'll accept anything like the following: hmm hhmm h:mm hh:mm in a 12 hour format. My problem is my test is ok'ing an input of 1300. Here is my test: if (0 == preg_match(/([0][1-9]|[1][0-2]|[1-9]):[0-5][0-9]/,$t)) return true; else return false; Can someone help me correct my regexp? I can not correct your regexp. But I must tell you that trying to tweak a regex for hours is surely **not productive**. If you got any type of text processing dont always go for regular expression. This problem can be solved just by simple string parsing. Here I have done that for you. function valid_time($time){ $m = (int) substr($time, -2); $h = (int) substr($time, 0, -2); return ($h=0 $h13 $m=0 $m60); } That won't work, it doesn't account for the possibility of a single digit hour field. I would do something like this: ?php $times = array( '100', # valid '1100', # valid '1300', # invalid '01:00',# valid '12:59',# valid '00:01',# valid '00:25pm', # invalid '', # valid 'a00', # invalid '00', # invalid ); foreach ( $times AS $time ) echo {$time} is .(valid_date($time)?'valid':'invalid').\n; function valid_date($time) { if ( ( $c_time = preg_replace('|[^\d:]+|', '', $time) ) !== $time ) return false; if ( ( $pos = strpos($c_time, ':') ) !== false ) { list($hour, $minute) = explode(':', $c_time, 2); } else { $break = (strlen($c_time) - 2); $hour = substr($c_time, 0, $break); $minute = substr($c_time, $break, 2); } $hour = (int)$hour; $minute = (int)$minute; if ( strlen($c_time) = 2 ) return false; if ( ( $hour = 0 $hour = 12 ) ( $minute = 0 $minute = 59 ) ) { return true; } return false; } It seems overly complicated, but it does check and error for the various things that I could think of for possible input. Give it a try and let us know. See it in action here. http://cmsws.com/examples/php/testscripts/shiplu@gmail.com/pt.php http://cmsws.com/examples/php/testscripts/shiplu@gmail.com/pt.phps Jim Lucas -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] regexp novice
Jim Lucas li...@cmsws.com wrote in message news:4fb5b89e.8050...@cmsws.com... On 5/17/2012 1:57 PM, shiplu wrote: On Fri, May 18, 2012 at 2:37 AM, Jim Ginerjim.gi...@albanyhandball.comwrote: ok - finally had to come up with my own regexp - and am failing. Trying to validate an input of a time value in the format hh:mm, wherein I'll accept anything like the following: hmm hhmm h:mm hh:mm in a 12 hour format. My problem is my test is ok'ing an input of 1300. Here is my test: if (0 == preg_match(/([0][1-9]|[1][0-2]|[1-9]):[0-5][0-9]/,$t)) return true; else return false; Can someone help me correct my regexp? I can not correct your regexp. But I must tell you that trying to tweak a regex for hours is surely **not productive**. If you got any type of text processing dont always go for regular expression. This problem can be solved just by simple string parsing. Here I have done that for you. function valid_time($time){ $m = (int) substr($time, -2); $h = (int) substr($time, 0, -2); return ($h=0 $h13 $m=0 $m60); } That won't work, it doesn't account for the possibility of a single digit hour field. I would do something like this: ?php $times = array( '100', # valid '1100', # valid '1300', # invalid '01:00',# valid '12:59',# valid '00:01',# valid '00:25pm', # invalid '', # valid 'a00', # invalid '00', # invalid ); foreach ( $times AS $time ) echo {$time} is .(valid_date($time)?'valid':'invalid').\n; function valid_date($time) { if ( ( $c_time = preg_replace('|[^\d:]+|', '', $time) ) !== $time ) return false; if ( ( $pos = strpos($c_time, ':') ) !== false ) { list($hour, $minute) = explode(':', $c_time, 2); } else { $break = (strlen($c_time) - 2); $hour = substr($c_time, 0, $break); $minute = substr($c_time, $break, 2); } $hour = (int)$hour; $minute = (int)$minute; if ( strlen($c_time) = 2 ) return false; if ( ( $hour = 0 $hour = 12 ) ( $minute = 0 $minute = 59 ) ) { return true; } return false; } It seems overly complicated, but it does check and error for the various things that I could think of for possible input. Give it a try and let us know. See it in action here. http://cmsws.com/examples/php/testscripts/shiplu@gmail.com/pt.php http://cmsws.com/examples/php/testscripts/shiplu@gmail.com/pt.phps Jim Lucas Thanks for the work you did, but I really wanted to try to solve this using the more elegant way, which from my readings over the last year as a new php developer, seemed to be the regexp methodology. I'm so close - it's only the 1300,1400,etc. time values that are getting by my expression. And thank you Shiplu also for your simple, but non-regexp, solution. Yes - it works and I had something similar that was just missing one more check when I decided to explore the regexp method. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] regexp novice
On 5/17/2012 8:07 PM, Jim Giner wrote: Jim Lucasli...@cmsws.com wrote in message news:4fb5b89e.8050...@cmsws.com... On 5/17/2012 1:57 PM, shiplu wrote: On Fri, May 18, 2012 at 2:37 AM, Jim Ginerjim.gi...@albanyhandball.comwrote: ok - finally had to come up with my own regexp - and am failing. Trying to validate an input of a time value in the format hh:mm, wherein I'll accept anything like the following: hmm hhmm h:mm hh:mm in a 12 hour format. My problem is my test is ok'ing an input of 1300. Here is my test: if (0 == preg_match(/([0][1-9]|[1][0-2]|[1-9]):[0-5][0-9]/,$t)) return true; else return false; Can someone help me correct my regexp? I can not correct your regexp. But I must tell you that trying to tweak a regex for hours is surely **not productive**. If you got any type of text processing dont always go for regular expression. This problem can be solved just by simple string parsing. Here I have done that for you. function valid_time($time){ $m = (int) substr($time, -2); $h = (int) substr($time, 0, -2); return ($h=0 $h13 $m=0 $m60); } That won't work, it doesn't account for the possibility of a single digit hour field. I would do something like this: ?php $times = array( '100', # valid '1100', # valid '1300', # invalid '01:00',# valid '12:59',# valid '00:01',# valid '00:25pm', # invalid '', # valid 'a00', # invalid '00', # invalid ); foreach ( $times AS $time ) echo {$time} is .(valid_date($time)?'valid':'invalid').\n; function valid_date($time) { if ( ( $c_time = preg_replace('|[^\d:]+|', '', $time) ) !== $time ) return false; if ( ( $pos = strpos($c_time, ':') ) !== false ) { list($hour, $minute) = explode(':', $c_time, 2); } else { $break = (strlen($c_time) - 2); $hour = substr($c_time, 0, $break); $minute = substr($c_time, $break, 2); } $hour = (int)$hour; $minute = (int)$minute; if ( strlen($c_time)= 2 ) return false; if ( ( $hour= 0 $hour= 12 ) ( $minute= 0 $minute= 59 ) ) { return true; } return false; } It seems overly complicated, but it does check and error for the various things that I could think of for possible input. Give it a try and let us know. See it in action here. http://cmsws.com/examples/php/testscripts/shiplu@gmail.com/pt.php http://cmsws.com/examples/php/testscripts/shiplu@gmail.com/pt.phps Jim Lucas Thanks for the work you did, but I really wanted to try to solve this using the more elegant way, which from my readings over the last year as a new php developer, seemed to be the regexp methodology. I'm so close - it's only the 1300,1400,etc. time values that are getting by my expression. And thank you Shiplu also for your simple, but non-regexp, solution. Yes - it works and I had something similar that was just missing one more check when I decided to explore the regexp method. How about this instead? pre?php $times = array( '100', # valid '1100', # valid '1300', # invalid '01:00',# valid '12:59',# valid '00:01',# valid '00:25pm', # invalid '', # valid 'a00', # invalid '00', # invalid ); foreach ( $times AS $time ) echo {$time} is .(valid_date($time)?'valid':'invalid').\n; function valid_date($time) { if ( ( $c_time = preg_replace('|[^\d\:]+|', '', $time) ) != $time ) return false; preg_match('#^(?Phour\d{1,2}):?(?Pminute\d{2})$#', $time, $m); if ( $m ( 0 = (int) $m['hour']12 = (int) $m['hour'] ) ( 0 = (int) $m['minute'] 59 = (int) $m['minute'] ) ) { return TRUE; } return false; } Let me know. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] regexp novice
On 5/17/2012 9:52 PM, Jim Lucas wrote: How about this instead? pre?php $times = array( '100', # valid '1100', # valid '1300', # invalid '01:00', # valid '12:59', # valid '00:01', # valid '00:25pm', # invalid '', # valid 'a00', # invalid '00', # invalid ); foreach ( $times AS $time ) echo {$time} is .(valid_date($time)?'valid':'invalid').\n; function valid_date($time) { if ( ( $c_time = preg_replace('|[^\d\:]+|', '', $time) ) != $time ) return false; preg_match('#^(?Phour\d{1,2}):?(?Pminute\d{2})$#', $time, $m); if ( $m ( 0 = (int) $m['hour'] 12 = (int) $m['hour'] ) ( 0 = (int) $m['minute'] 59 = (int) $m['minute'] ) ) { return TRUE; } return false; } Let me know. I optimized it a little... http://www.cmsws.com/examples/php/testscripts/shiplu@gmail.com/pt_regex.php http://www.cmsws.com/examples/php/testscripts/shiplu@gmail.com/pt_regex.phps pre?php $times = array( '100', # valid '1100', # valid '1300', # invalid '01:00',# valid '12:59',# valid '00:01',# valid '00:25pm', # invalid '', # valid 'a00', # invalid '00', # invalid ); foreach ( $times AS $time ) echo {$time} is .(valid_time($time)?'valid':'invalid').\n; function valid_time($time) { if ( preg_match('#^(\d{1,2}):?(\d{2})$#', $time, $m) ( 0 = (int) $m[1] 12 = (int) $m[1] ) ( 0 = (int) $m[2] 59 = (int) $m[2] ) ) { return TRUE; } return FALSE; } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] regexp novice
Jim L. I did't actually consider that wide range of time values. Here is an update. Still this can be written without help of regex. I must add one more thing that a '00:01' is invalid in 12 hour format. OP wants it to be 12-hour format. function valid_time($time){ $m = substr($time, -2); $h = (explode(':', substr($time, 0, -2))); $h = $h[0]; return (is_numeric($h) is_numeric($m) $h0 $h13 $m=0 $m60); } See the code in action here http://ideone.com/tSQIb -- Shiplu Mokaddim Talks: http://shiplu.mokadd.im Follow: http://twitter.com/shiplu Innovation distinguishes between follower and leader -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php