我正在與以下部分的PHP代碼。目的是將圖像文件從一臺服務器發佈到另一臺服務器。只要文件爲<〜250k,此功能就可以完美並且非常快速地工作。超過250k,處理時間跳到約60秒,並從那裏增加圖像大小。奇怪的延遲發佈從PHP fsockopen
任何想法?
謝謝!
約翰
$fileContents = file_get_contents($_FILES[$key]['tmp_name']);
$time = strtotime("now");
$body = "--f6sd54c2
Content-Disposition: form-data; name=\"id\"
Content-Length: " . strlen($id) . "
{$id}
--f6sd54c2
Content-Disposition: form-data; name=\"key\"
Content-Length: " . strlen("654t2bsr65t42czd13fvs6dry87") . "
654t2bsr65t42czd13fvs6dry87
--f6sd54c2
Content-Disposition: form-data; name=\"time\"
Content-Length: " . strlen($time) . "
{$time}
--f6sd54c2
Content-Disposition: form-data; name=\"photo\"; filename=\"photo.jpg\"
Content-Type: image/jpeg
Content-Length: " . strlen($fileContents) . "
{$fileContents}
--f6sd54c2--";
$headers = "POST /photos/process.php HTTP/1.1
Host: www.hostname.com
Keep-Alive: 300
Connection: keep-alive
Content-Type: multipart/form-data; boundary=f6sd54c2
Content-Length: " . strlen($body) . "
";
$fp = fsockopen("www.hostname.com", 80, $errno, $errstr);
if ($fp){
fwrite($fp, $headers . $body);
fclose($fp);
}
服務器之間的連接是什麼?他們是在同一個本地網絡,一個灣,還是通過網絡? – Cryophallion 2010-01-21 17:38:21