This is a discussion on PHP Alarm/Timeout function? within the alt.comp.lang.php forums, part of the PHP Programming Forums category; I've looked back at some old posts, and all seem to point to no answer for this. These posts ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
I've looked back at some old posts, and all seem to point to no answer for
this. These posts were old so I'm wondering if there if someone has come up with anything new lately. Basically I have one PHP command line script that uses the exec funtion to open a 2nd PHP script. The 2nd PHP script runs the 'mount' command to mount some cifs shares. Occasionally the mount command will hang on certain shares of computers. Is there anyway that I can timeout an exec command so that it continues on? I thought a read something about being able to timout backticks? I can use backticks if needed, but I'm not sure how that works. Thanks, Max |
|
|||
|
Easynews wrote: > I've looked back at some old posts, and all seem to point to no answer for > this. These posts were old so I'm wondering if there if someone has come up > with anything new lately. > > Basically I have one PHP command line script that uses the exec funtion to > open a 2nd PHP script. The 2nd PHP script runs the 'mount' command to mount > some cifs shares. Occasionally the mount command will hang on certain shares > of computers. Is there anyway that I can timeout an exec command so that it > continues on? I thought a read something about being able to timout > backticks? I can use backticks if needed, but I'm not sure how that works. > > Thanks, > Max Did you look in the manual under exec() ? <http://us3.php.net/manual/en/function.exec.php> "Note: If you start a program using this function and want to leave it running in the background, you have to make sure that the output of that program is redirected to a file or some other output stream or else PHP will hang until the execution of the program ends." |
|
|||
|
"ZeldorBlat" <zeldorblat@gmail.com> wrote in message news:1134272377.896009.228450@z14g2000cwz.googlegr oups.com... > > Easynews wrote: >> I've looked back at some old posts, and all seem to point to no answer >> for >> this. These posts were old so I'm wondering if there if someone has come >> up >> with anything new lately. >> >> Basically I have one PHP command line script that uses the exec funtion >> to >> open a 2nd PHP script. The 2nd PHP script runs the 'mount' command to >> mount >> some cifs shares. Occasionally the mount command will hang on certain >> shares >> of computers. Is there anyway that I can timeout an exec command so that >> it >> continues on? I thought a read something about being able to timout >> backticks? I can use backticks if needed, but I'm not sure how that >> works. >> >> Thanks, >> Max > > Did you look in the manual under exec() ? > > <http://us3.php.net/manual/en/function.exec.php> > > "Note: If you start a program using this function and want to leave it > running in the background, you have to make sure that the output of > that program is redirected to a file or some other output stream or > else PHP will hang until the execution of the program ends." Yes, I saw this, but can not figure out how to get it to work. I've also tried the following that I found in an older post that was supposed to do the trick, but it didn't work either, the original PHP script still hangs: proc_close(proc_open ("mount -r -t cifs -o user=$adminuser,pass=$adminpass,domain=$domain //$ip/$sha rename $sharedir/$hostname/$sharename &", array(), $foo)); Any other suggestions? Thanks, Max |
|
|||
|
>> "Note: If you start a program using this function and want to leave it
>> running in the background, you have to make sure that the output of >> that program is redirected to a file or some other output stream or >> else PHP will hang until the execution of the program ends." For some reason the following worked: <?php // t.php echo "going"; `nohup ls -alR / > /dev/null &`; echo "\ndone"; ?> %> php t.php going done %> But when I added error redirection it failed (to continue the php script): <?php // t.php echo "going"; `nohup ls -alR / 2>&1 > /dev/null &`; echo "\ndone"; ?> %> php t.php going (PHP still waits for exec or `` to complete) -- Etienne Marais Cosmic Link South Africa |
|
|||
|
I appreciate your input. Thanks to your post, I was actually able to go a
little further to get what I'm looking for with the following: #!/usr/bin/php -q <? $pid = exec("mount ... > mount.$hostname.log & echo \$!"); print $pid."\n"; ?> This way I've got a log, and the PID. With the testing I've done so far, the script does not hang. Thanks again... "Etienne Marais" <etienne@cosmiclink.co.za> wrote in message news:dnkgto$kbq$1@ctb-nnrp2.saix.net... >>> "Note: If you start a program using this function and want to leave it >>> running in the background, you have to make sure that the output of >>> that program is redirected to a file or some other output stream or >>> else PHP will hang until the execution of the program ends." > > For some reason the following worked: > > <?php > // t.php > > echo "going"; > `nohup ls -alR / > /dev/null &`; > echo "\ndone"; > > ?> > > %> php t.php > going > done > %> > > > > But when I added error redirection it failed (to continue the php script): > > <?php > // t.php > > echo "going"; > `nohup ls -alR / 2>&1 > /dev/null &`; > echo "\ndone"; > > ?> > > %> php t.php > going > > > (PHP still waits for exec or `` to complete) > > > -- > Etienne Marais > Cosmic Link > South Africa > |