PHP Alarm/Timeout function?

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 ...


Go Back   Usenet Forums > PHP Programming Forums > alt.comp.lang.php

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 12-11-2005
Easynews
 
Posts: n/a
Default PHP Alarm/Timeout function?

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


Reply With Quote
  #2 (permalink)  
Old 12-11-2005
ZeldorBlat
 
Posts: n/a
Default Re: PHP Alarm/Timeout function?


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."

Reply With Quote
  #3 (permalink)  
Old 12-12-2005
Easynews
 
Posts: n/a
Default Re: PHP Alarm/Timeout function?


"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


Reply With Quote
  #4 (permalink)  
Old 12-12-2005
Etienne Marais
 
Posts: n/a
Default Re: PHP Alarm/Timeout function?

>> "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

Reply With Quote
  #5 (permalink)  
Old 12-12-2005
Easynews
 
Posts: n/a
Default Re: PHP Alarm/Timeout function?

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
>



Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 11:58 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0