O
O
odiszapc2011-08-03 10:15:11
PHP
odiszapc, 2011-08-03 10:15:11

Why is PHP exec() so slow?

I noticed a long time ago that any resource-intensive operations performed through the PHP exec() function take many times, and sometimes an order of magnitude more time than a call from the console.
For example, image-magic's convert works ten times slower than a call from the console.
Has anyone come across? How to bypass it? Push calls from PHP through a queuing system? What options exist? And most importantly, why is this happening?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Sergey Belov, 2011-08-03
@BeLove

has this method been tested?

<?
`echo hello > ~/hello`
?>
I use it, no problem. I don't know the exact differences from shell_exec, exec, system.

N
Nastradamus, 2011-08-03
@Nastradamus

Mm. And try shell_exec() in this way: Script some_script.sh to teach how to set up semaphores, and then somehow query the execution status of the script via AJAX.
$e = "/usr/bin/nohup /home/work/some_script.sh > /dev/null 2>&1 &";
shell_exec("$e");

I
Igor Zubarev, 2018-07-23
@igor32

Try this way:

$cmd = 'git log';
$result = null;
$process = proc_open($cmd, [1 => ['pipe', 'w']], $pipes, null, null, array('suppress_errors' => true));
if (\is_resource($process)) {
    $result = stream_get_contents($pipes[1]);
    fclose($pipes[1]);
    proc_close($process);
}
        
var_dump($result);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question