Forum Moderators: coopster

Message Too Old, No Replies

shell_exec using system tools - wait for process to finish

unix shell_exec() commandline

         

Snurk

1:50 am on Aug 14, 2005 (gmt 0)

10+ Year Member



Hello everyone!

I have a problem that hopefuly someone here knows the answer to. I want to do a shell_exec command from PHP.

I then want to continue with the script when the shell program is finished with what it does. Problem here is, that will take approximately one hour. How do I make the script wait until the program that I call in shell_exec is finished?

Any help is appreciated!

Thanx for taking time to read this,

Erik / SNURK

softwareengineer99

2:03 am on Aug 14, 2005 (gmt 0)

10+ Year Member



There are couple ways of doing that but the simplest one will be to try increasing your PHP script's time limit (if you have safe mode turned off).
Search PHP.net for set_time_limit function.

Snurk

2:35 am on Aug 14, 2005 (gmt 0)

10+ Year Member



Ah, yes, thanks for that! Will sure be useful. However, here comes another issue (and perhaps a silly question): How does the script know when the program I executed through shell_exec is finished?

softwareengineer99

2:38 am on Aug 14, 2005 (gmt 0)

10+ Year Member



Depending on your needs and experience, you may
-have your shell script update an intermediary table or file to indicate it's finished executing.
-use shared memory (not recommended, unless you know what you are doing)

Snurk

11:07 am on Aug 14, 2005 (gmt 0)

10+ Year Member



Ah yes, you mean having it checking a MySQL table or a textfile for every 5 min or so?

Only thing now is, the file that the program generates will probably be 100+ mb. I know is_file() checks if a file exists, is there a way to check if the file is currently open?

I am unfamiliar with UNIX file creation, and I am not sure how to create a specific file that says it is finished.

Thanx!

Erik / SNURK

Snurk

11:22 am on Aug 14, 2005 (gmt 0)

10+ Year Member



actually, I think I know of asolution, just have a:

shell_exec('echo '<?php $status = "working";?>' > status.txt');

:-)