You are here: Re: Time Out an Exec Call « All PHP « IT news, forums, messages
Re: Time Out an Exec Call

Posted by Tyrone Slothrop on 05/31/06 15:24

On Tue, 30 May 2006 16:22:44 -0500, "robert"
<ab@no.spam-alama-ding-dong> wrote:

>do you have an example for us to look at? on php.net there are several
>examples of how to essentially multithread php exec's. the best solution
>will perhaps avail itself with a bit more detail from you.
>
>cheers.

Just leave me out of the flames, OK? Personally, I don't care about
top posting (I do it all of the time, but not here) as long as I can
get an idea of how to approach this problem.

I ws trying to avoid having to give too much detail since this is a
rather unique coding application. The problem is that I need to have
a timer in here to stop any process that is taking too long to
complete. It would be easier if pcntl was installed on this box, but
it isn't and the client is not thrilled about installing it in a
producttion environment. (understatement)

StarOS is an app which is installed on routers, servers and related
devices which provides diagnostic utilities for configuration and
connectivity. There are a number of utilities which generate files
containing configuration data which we are storing on a server within
a an ISP's network as a backup in the event of failure.

Here is the function which actually does the tests. The data for
these tests is stored in a MySQL database, each IP having its own
record. The tests which are applied to a given IP are determined by
the $test_ids, which is passed as an array of id numbers corresponding
to keys of an array of all possible tests. Debug code is still in
here (echoes and the like).

function starutil_exec
($star,$ip,$pwd,$path,$ispid,$date,$test_ids,$servdat)
{
### Creates directories
### Structure: /ISP/date/IP/
$ipdir = str_replace (".","-",$ip);
if (!is_dir("$path/$ispid")) {
if (!mkdir("$path/$ispid")) {
echo "$path/$ispid failed\n";
return 0;
}
}
if (!is_dir("$path/$ispid/$date")) {
if (!mkdir("$path/$ispid/$date")) {
echo "$path/$ispid/$date failed\n";
return 0;
} else {
chmod ("$path/$ispid/$date", 0777);
}
}
if (!is_dir("$path/$ispid/$date/$ipdir")) {
if (!mkdir("$path/$ispid/$date/$ipdir")) {
echo "$path/$ispid/$date/$ipdir failed\n";
return 0;
}
}

### Possible tests:
$tests =
array('cbq','fw','nat','proxy','dhcpd','rad_users','rad_nas');

### Define $x-1 as number of possible tries
$x = 2;

### $test_ids is an array of numbers
### corresponding to keys of $tests
foreach ($test_ids as $i) {
if (!is_file("$path/$ispid/$date/$ipdir/{$tests[$i]}.txt")) {

### This is the exec() that is timing out
$result = exec ("$star/starutil $ip $pwd -dscr {$tests[$i]}
$path/$ispid/$date/$ipdir/{$tests[$i]}.txt");
echo "$result\n";
if (substr ($result, 0, 26) == "Unable to talk with server" ||
substr ($result, 0, 16) == 'Invalid password') {
if ($x != 0) {
$i--; $x--; $continue;
} else {
if (is_dir("$path/$ispid/$date/$ipdir")) {
unlink("$path/$ispid/$date/$ipdir"); }
return $ip;
break;
}
}
### sleep before next test
usleep (500000);
}
}
if ($servdat) {
exec ("$star/starutil $ip $pwd -d
$path/$ispid/$date/$ipdir/server.dat");
}
}

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация