php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #55221 shell_exec works very slow with Apache
Submitted: 2011-07-17 12:56 UTC Modified: 2011-07-17 13:51 UTC
From: osmanungur at gmail dot com Assigned:
Status: Not a bug Package: Performance problem
PHP Version: 5.3.6 OS: Mac OS X 10.6.8
Private report: No CVE-ID: None
 [2011-07-17 12:56 UTC] osmanungur at gmail dot com
Description:
------------
Running commands with shell_exec in browser is working very slower than CLI. I'm 
having same problem with system() and proc_open(). 

Running from shell takes 0.11 sec, but running from browser takes 16.96 second. 
I tested out same code in Linux Ubuntu, same problem happens. 

CLI
------------

float(0.11125087738037)
string(211) "graph_left = 67
graph_top = 33
graph_width = 800
graph_height = 200
image_width = 882
image_height = 273
graph_start = 1310835249
graph_end = 1310921349
value_min = 0.0000000000e+00
value_max = 1.1000000000e+00
"

Browser / Apache
------------

float 16.960417032242
string 'graph_left = 67
graph_top = 33
graph_width = 800
graph_height = 200
image_width = 882
image_height = 273
graph_start = 1310834364
graph_end = 1310920464
value_min = 0.0000000000e+00
value_max = 1.1000000000e+00
' (length=211)

Test script:
---------------
<?php

$start = microtime(1);
$output = shell_exec($executor->getCommandString());
$end = microtime(1);
var_dump($end - $start, $output);


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-07-17 13:51 UTC] rasmus@php.net
-Status: Open +Status: Bogus
 [2011-07-17 13:51 UTC] rasmus@php.net
There really isn't anything we can do about that. When you run something from the 
command line your shell is already running and ready to go. When you do it from 
within PHP via any of those calls you need to fork and then exec the shell 
executable first and then run the command. That is a huge amount of overhead, 
especially if you are low on ram. To avoid the fork+exec overhead you should use 
some sort of pre-forking mechanism and simply pass messages to the already 
running job worker. You can roll your own, but I would suggest looking at 
something like Gearman instead.
 [2018-01-29 16:24 UTC] fortwebsolutions at gmail dot com
see last answer of https://stackoverflow.com/questions/14277910/php-exec-performance/48505455#48505455
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat May 18 23:01:31 2024 UTC