0
A
回答
0
無論是方式應該很快。
http://www.ebrueggeman.com/blog/php_benchmarking_fopen
這不是更好。
0
確實沒有辦法讓您的請求更快。如果數據變化不大,你可以做的就是在本地緩存數據。
僞代碼:
if (get_modification_time_of_file('cached.json') < time() - 300) {
download_file()
} else {
read_locally()
}
0
您有2個選項。
1:通過使用則fopen /的file_get_contents功能(多個)
2:通過設置一個客戶端網橋併發送它通過使用AJAX POST方法到PHP。然後使用json_decode在PHP上獲取它。
1
做一些簡單的標杆:
<?php
$start = microtime(true);
for ($i=0;$i<=10;$i++){
$handle = fopen("http://example.com/", "r");
while (!feof($handle)) {
$result .= fread($handle, 1024);
}
fclose($handle);
}
$end = microtime(true);
$time = $end - $start;
echo "Did fopen test in $time seconds<br />\n";
?>
難道的fopen試驗6.1602981090546秒
<?php
//file_get_contents is basically a wrapper for the above fopen so hence not much of a difference
$start = microtime(true);
for ($i=0;$i<=10;$i++){
$result = file_get_contents('http://example.com');
}
$end = microtime(true);
$time = $end - $start;
echo "Did file_get_contents test in $time seconds<br />\n";
?>
的file_get_contents有沒有在6.5289459228516秒
<?php
$start = microtime(true);
for ($i=0;$i<=10;$i++){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://example.com");
curl_setopt($ch, CURLOPT_HEADER, 0);
$result = curl_exec($ch);
}
$end = microtime(true);
$time = $end - $start;
echo "Did cUrl test in $time seconds<br />\n";
?>
測試
難道cUrl作者試驗2.9657130241394秒
捲曲勝手了......時間去尋找更好的主機
相關問題
- 1. 閱讀JSON文件
- 2. 閱讀JSON文件
- 3. 閱讀JSON文件?
- 4. 閱讀JSON文件
- 5. 閱讀JSON文件在python
- 6. 在閱讀json文件
- 7. 在線閱讀XML文件
- 8. 閱讀在線JSON的Android
- 9. 在jQuery閱讀json文件在javascript中
- 10. 在Go中閱讀json文件的值
- 11. JavaScript/jquery閱讀json文件
- 12. 如何閱讀JSON文件
- 13. 如何閱讀JSON文件?
- 14. 從JSON文件C#閱讀
- 15. 閱讀嵌套JSON文件
- 16. 閱讀JSON文件星火
- 17. 閱讀本地json文件
- 18. 閱讀json文件與readAsText「JSON錯誤」
- 19. Xamarin - 閱讀JSON文件並讀取值
- 20. 閱讀Python中的JSON格式文件
- 21. 閱讀Java中的json文件
- 22. 閱讀react.js中的JSON文件
- 23. 閱讀與GSON庫中的JSON文件
- 24. 如何閱讀java中的json文件
- 25. 閱讀用U JSON文件」中的R
- 26. 閱讀文件python中的水平線
- 27. 使用JENA在線閱讀rdf文件
- 28. 閱讀txt文件的在線
- 29. java/javascript在線閱讀XML文件
- 30. 在線閱讀文章
也許從服務器的響應速度很慢?你可以做的事情不多。你可以緩存數據,所以你不必爲每個請求進行外部呼叫? – AndrewR 2012-04-09 15:28:16