Bug #73412 [NEW]: get_headers terrible slow

From: Date: Fri, 28 Oct 2016 14:06:44 +0000
Subject: Bug #73412 [NEW]: get_headers terrible slow
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-205054@lists.php.net to get a copy of this message
From:             spam2 at rhsoft dot net
Operating system: Linux
PHP version:      7.0.12
Package:          Performance problem
Bug Type:         Bug
Bug description:get_headers terrible slow

Description:
------------
may someone explain me why PHP is that terrible slow with the
test-script below doing 150 HTTP-calls on a local webserver where the 50
most expensive CMS requests take only 5037 us (the header which i want
to parse out to measure the difference between cms, htm-file and
htm-file with .php extension comes from httpd - Header always set
"X-Response-Time" "%D us") 

40 seconds for 150 requests - on a machine which can "ab -c 20 -n 100000
http://localhost/" handle 1200 per second?

[harry@srv-rhsoft:/downloads]$ time php -r
"get_headers('http://corecms/static.htm');"
real    0m0.040s
user    0m0.026s
sys     0m0.013s

[harry@srv-rhsoft:/downloads]$ time wget http://corecms/static.htm
real    0m0.006s
user    0m0.002s
sys     0m0.003s


Test script:
---------------
[harry@srv-rhsoft:/downloads]$ time php
/www/corecms.rhsoft.net/response-times.php
COUNT:       50
DYNAMIC CMS: 5037 us
STATIC HTM:  346 us
STATIC PHP:  1645 us
FACTOR D/S:  14.6
FACTOR P/S:  4.8
FACTOR D/P:  3.1

real    0m39.557s
user    0m0.059s
sys     0m0.043s
________________________________________

[harry@srv-rhsoft:/downloads]$ cat
/www/corecms.rhsoft.net/response-times.php
#!/usr/bin/php
<?php
 if(PHP_SAPI == 'cli')
 {
  $dynamic  = array();
  $static   = array();
  $staticp  = array();
  $requests = 50;

  for($count=1; $count<=$requests; $count++)
  {
   $dynamic[] = get_repsonse_time('http://corecms/index.php');
   $static[]  = get_repsonse_time('http://corecms/static.htm');
   $staticp[] = get_repsonse_time('http://corecms/static.php');
  }
  $dynamic_sum = array_sum($dynamic);
  $static_sum  = array_sum($static);
  $staticp_sum  = array_sum($staticp);
  $dynamic_avg = $dynamic_sum / count($dynamic);
  $static_avg  = $static_sum / count($static);
  $staticp_avg = $staticp_sum / count($staticp);
  echo 'COUNT:       ' . count($dynamic) . "\n";
  echo 'DYNAMIC CMS: ' . round($dynamic_avg) . " us\n";
  echo 'STATIC HTM:  ' . round($static_avg) . " us\n";
  echo 'STATIC PHP:  ' . round($staticp_avg) . " us\n";
  echo 'FACTOR D/S:  ' . round($dynamic_avg / $static_avg, 1) . "\n";
  echo 'FACTOR P/S:  ' . round($staticp_avg / $static_avg, 1) . "\n";
  echo 'FACTOR D/P:  ' . round($dynamic_avg / $staticp_avg, 1) . "\n";
 }

 function get_repsonse_time($url)
 {
  $response = get_headers($url, 1);
  $response = explode('D=', $response['X-Response-Time']);
  return (int)trim(str_replace(' us', '', $response[1]));
 }
?>


-- 
Edit bug report at https://bugs.php.net/bug.php?id=73412&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=73412&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=73412&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=73412&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=73412&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=73412&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=73412&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=73412&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=73412&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=73412&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=73412&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=73412&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=73412&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=73412&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=73412&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=73412&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=73412&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=73412&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=73412&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=73412&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=73412&r=mysqlcfg



Thread (19 messages)

« previous php.bugs (#205054) next »