Page 1 of 1

Using PHP exec() or similar

Posted: Fri Oct 15, 2004 5:53 am
by mjseaden
Sami | Help us, help you. Please use

Code: Select all

and

Code: Select all

tags where approriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Dear All,

Is there a PHP command, such as [php_man]exec()[/php_man], that I can use that will suspend operation until the completion and termination of the command given in exec(). To give an example;

Code: Select all

<?php
exec('sleep 10');
?>
on a UNIX machine does not wait for 10 seconds before continuing operation. Is there a way in which I can do this? It's pretty important!

Many thanks,

Mark

Posted: Fri Oct 15, 2004 6:04 am
by mudkicker
[php_man]sleep[/php_man]()

Posted: Fri Oct 15, 2004 6:24 am
by mjseaden
Hi mudkicker,

I'm talking about a generic approach. I simply want a shell execution command that doesn't continue processing the PHP script until after the command has been executed.

So for instance above, I would want the PHP script to suspend execution for 10 seconds. exec() would start, and then wait until the command had finished before resuming the PHP script. In this sense, if I echoed 'start' before exec() and 'finish' after there would be a 10 second delay between echoing 'start' and 'finish'.

Also, exec() doesn't seem to report any errors even if I put a random program that doesn't exist into its brackets ().

Any ideas what's wrong?

Many thanks

Mark

Posted: Fri Oct 15, 2004 7:56 am
by phpScott
couldn't you just put the exec() in a if() or while loop to stop the rest of the php script from running while the command is doing its thing?

there is also [php_man]passthru[/php_man] and [php_man]system[/php_man] that might do what you are looking for.

Posted: Fri Oct 15, 2004 8:27 am
by mjseaden
Hi phpScott, I'm actually now using system('cmd', $retval).

The return value is consistently reporting as 127, with no varience whether I put a random program (non-existant) command into system() or one that exists. The last line, which system(), always returns an empty string.

I've noticed from phpinfo() that the server is currently running in safe mode - could this be anything to do with it? Is there something else that I should be looking for?

Cheers, Mark

Posted: Fri Oct 15, 2004 8:38 am
by twigletmac
You should have a look through this:
http://php.net/manual/en/features.safe- ... ctions.php

Safe mode does restrict or disable certain functions.

Mac