Jump to content

getting more efficiency out of the exec() function


ronman

Recommended Posts

Hi,

I'm new to phpfreaks and looking forward to learning and contributing lots of good stuff.

 

Here's my problem:  I'm running a binary (the excellent graphviz) from PHP using the exec() function.  But it's about 40x slower than running the same binary from a command line.  The system is RedHat/apache.

 

what can be done?  This is too slow.

 

Here's more:

From a command line, I use strace to see how fast Graphviz runs.  It can render my largest image from a shell command line in 0.02 seconds.

 

strace says that it runs in exactly the same time, sometimes less, when called by exec().  That is, by running the following in PHP:  exec( strace -c <graphviz command>)

 

But putting timing statements around exec():

display_time(...)

exec(<graphviz command>)

display_time(...)

 

reveals that it takes about 0.8 seconds to return from the exec(), even though what has executed within the exec only takes 0.02 or less.  These values have been fairly consistent for months.

 

>:(

 

There must be a better way.

 

(i even thought of using inotify to run graphviz outside of PHP whenever PHP wrote out a file, but the version of RedHat I'm tied to doesn't support inotify).

 

Thanks in advance.

 

Ron

 

So exec() always increases the time to execute whatever it calls by 40x?  Say it isn't so.  There must be some memory allocation issue that could be addressed.

 

Or perhaps running PHP as a CGI in Apache is the problem rather than running it as an Apache module.  Has anyone experimented with this?

 

(I'm using PHP 4.4.6, and the hosting company updates to the latest version of Apache whatever it is)

 

Ron

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.