<?php
set_time_limit(0);
$errorArr = array();
if (!isset($argv[1]))
{
array_push($errorArr, "You forgot to enter a host.");
}
if ((isset($argv[1])) AND (!filter_var($argv[1], FILTER_VALIDATE_IP)))
{
array_push($errorArr, "The host you entered is not a valid IP address.");
}
if (!isset($argv[2]))
{
array_push($errorArr, "You forgot to select a port.");
}
if (!empty($errorArr))
{
echo "You have the following errors:\n";
print_r($errorArr);
die("Syntax is as follows: php {$argv[0]} host port\n");
}
$host = $argv[1];
$port = $argv[2];
echo ":::Connecting...\n";
$fh = fsockopen($host, $port);
if (!$fh)
{
die(":::Connection failed.\n:::Aborting.\n");
}
echo ":::Connected!\n:::Sending headers.\n";
$header = "PROPFIND /webdav/ HTTP/1.1\r\n";
$header .= "Host: {$host}\r\n";
$header .= "User-Agent: BitKinex/3.2.3\r\n";
$header .= "Accept: */*\r\n";
$header .= "Pragma: no-cache\r\n";
$header .= "Cache-Control: no-cache\r\n";
$header .= "Depth: 1\r\n";
$header .= "Content-Length: 220\r\n";
$header .= "Content-Type: text/xml\r\n\r\n\r\n";
if (!fwrite($fh, $header))
{
die(":::Couldn't send headers. Aborting.\n");
}
$exHeader = explode("\r\n", $header);
foreach ($exHeader as $ecHeader)
{
echo "<<<{$ecHeader}\n";
}
echo "\n:::Retrieving syntax...\n";
while(1)
{
while ($data = fgets($fh, 512))
{
echo ">>>{$data}";
flush();
}
}
?>
我正在處理腳本以連接到WebDAV,上傳文件並斷開連接。它很好地連接和發送頭文件,但是它會永久性地檢索語法。有時,這需要幾分鐘,我不明白爲什麼。這是我的代碼中的問題嗎?爲什麼我的腳本需要這麼長時間才能檢索標題?
是的,我意識到有一個無限的while循環。這是有目的的,因爲我還沒有想出如何知道服務器何時完成向我發送信息。所以我想這是另一個問題,如果任何人都可以提供這方面的見解。
感謝
聽起來像是適合xdebug或其他php分析器的時候。 xdebug會告訴你你的代碼花費了多少時間。我的猜測是你最終會得到一個花費時間的fopen/socket調用,但這只是一個預感。 – Chris 2010-11-17 14:44:49
@Rob - 請在代碼的不同層次添加,至少它可以幫助您確定哪個部分掛起了 – ajreal 2010-11-17 14:47:46
對於mea來說看起來不錯,如果您使用telnet? – 2010-11-17 14:49:46