如下,我有一個頁面,要展示圖片資訊,但getimagesize時間太長了,有其他高效的方法嗎?
我是擷取圖片資訊,不是查看存不存在
回複內容:
如下,我有一個頁面,要展示圖片資訊,但getimagesize時間太長了,有其他高效的方法嗎?
我是擷取圖片資訊,不是查看存不存在
問題是這樣的。這個事情給PHP做絕對是個坑。
流量上來了,圖片來源站點不穩定了,網路出問題了,分分鐘搞死伺服器。
可以問前端大神有沒有方案,或折中辦法。
如果沒有的話,可以在資料庫建個表,維護一份圖片資訊資料。
然後當有圖片加入的時候,就先判斷表是否有資料了,如果沒有擷取圖片的大小資訊存入表,然後再做後面操作。
頁面顯示的時候直接查出來。
這裡不說緩衝,不說隊列,不說圖片本地化(而不是使用他站圖片),是因為看起來這些會大大增加複雜度,當有必要的時候再考慮。
V2站上不是有大神已經提出解決方案了嗎?
http://v2ex.com/t/286977#reply17
getImageInfo 試試
getimagesize時間太長,可能是因為你頻寬太低,或者是圖片伺服器響應速度慢導致的
抄了條評論
getimagesize
As noted below, getimagesize will download the entire image before it checks for the requested information. This is extremely slow on large images that are accessed remotely. Since the width/height is in the first few bytes of the file, there is no need to download the entire file. I wrote a function to get the size of a JPEG by streaming bytes until the proper data is found to report the width and height: