0

I need solve my problem with check external XML file in short time. If i use function if (fopen($sxml[$looppocet], "r")) and I have more XML files forexample 15 so this take a very long time and I need config execution time but this is very bad solved. I need check one file if this file is exist then continue go in my cycle if not so print my error and next step next file too.

Please how can I solve this problem?

4

1 回答 1

0

我的解决方案是...我使用此功能检查了外部设备上的 ping。

function icmpChecksum($data){
if (strlen($data)%2)
$data .= "\x00";

$bit = unpack('n*', $data);
$sum = array_sum($bit);

while ($sum >> 16)
$sum = ($sum >> 16) + ($sum & 0xffff);

return pack('n*', ~$sum);
}
// Making the package
$type= "\x08";
$code= "\x00";
$checksum= "\x00\x00";
$identifier = "\x00\x00";
$seqNumber = "\x00\x00";
$data= "Scarface";
$package = $type.$code.$checksum.$identifier.$seqNumber.$data;
$checksum = icmpChecksum($package); // Calculate the checksum
$package = $type.$code.$checksum.$identifier.$seqNumber.$data;
// And off to the sockets
$socket = socket_create(AF_INET, SOCK_RAW, 1);
socket_set_option ( $socket, SOL_SOCKET, SO_RCVTIMEO, array("sec"=>1, "usec"=>0) );
socket_connect($socket, 192.168.0.1, null);
$startTime = microtime(true);
socket_send($socket, $package, strLen($package), 0);
if (false === (@socket_read($socket, 255))) {       
            echo "Harddware is OFF--->";
    } else {
            echo "Harddware is ON--->";
           }

如果我使用带有 shell 功能的经典 ping,那么这对我来说完全不稳定 :)

于 2013-07-01T12:23:04.310 回答