- 以下的 $ch 指的是 php curl_init() 傳回的 resource(cURL handle) ,同等於 libcurl 的 easy-handle,$mh 以此類推。
- $ch 在加入 $mh 之後就不能重覆使用(意指僅用 curl_setopt() 重設 URL)了,得關掉後重新初始化再來。
- $ch 在加入 $mh 之後 curl_errno() 會失效(總是傳回 int(0),原因不明),而 curl_error() 則是有些錯誤抓不到(已知 CURLE_COULDNT_RESOLVE_HOST(6) 不行)。
- 承上, 改用 curl_multi_info_read() 替代。傳回值如下:
<?php $curlmsg = curl_multi_info_read($mh); var_dump( $curlmsg ); // 當沒有訊息時傳回 boolean(false) // 反之則傳回 array(3) { ["msg"]=> int(1) ["result"]=> int(0) ["handle"]=> resource(9) of type (curl) } ?>
- $curlmsg["msg"] 目前只有定義 CURLMSG_DONE(1) 一值,暫時可以不用理它。
- $curlmsg["result"] 值為 CURLE_* 之一。
- $curlmsg["handle"] 訊息來源的 $ch。
- curl_multi_info_read() 較為明確的呼叫時機,是當執行 curl_multi_exec($mh, $rh) 之後, $rh 變動(減少)的時候。
- curl_multi_select() 並非必要的,呼叫的主要目地是為了先檢查開啟的 sockets 有無資料,再做對應的動作,以減少佔用的 CPU 資源。以下為 Unix Socket FAQ 摘錄:
2.9. What are the pros/cons of select(), non-blocking I/O and SIGIO? Using non-blocking I/O means that you have to poll sockets to see if there is data to be read from them. Polling should usually be avoided since it uses more CPU time than other techniques. Using SIGIO allows your application to do what it does and have the operating system tell it (with a signal) that there is data waiting for it on a socket. The only drawback to this soltion is that it can be confusing, and if you are dealing with multiple sockets you will have to do a select() anyway to find out which one(s) is ready to be read. Using select() is great if your application has to accept data from more than one socket at a time since it will block until any one of a number of sockets is ready with data. One other advantage to select() is that you can set a time-out value after which control will be returned to you whether any of the sockets have data for you or not.
- [comp.unix.programmer] Unix-socket-faq for network programming
歡迎來到小豬圈!
2007-12-30
關於 php_curl (二)
Subscribe to:
Post Comments (Atom)
Blog Archive
-
▼
2007
(140)
-
▼
December
(23)
- 關於 php_curl (二)
- 廣告插播? - HiNet 線上通知服務同意書
- 踩地雷電影版
- 關於 php_curl
- 關於 meeya
- 監獄兔 ウサビッチ|USAVICH.TV
- 關於 PHP Constants (常數)
- Yahoo UI 是好物
- 安裝 VMware 與 CentOS
- (X)HTML content-type 的選擇
- 紀曉君與家家演唱的 Santa Lucia
- MySQL Index 長度限制為 1000 “bytes”
- 看看為什麼人家拍的好
- 字字珠璣
- 初試 Google Code - Project Hosting 提供 svn 服務
- Charset (字元集)的選擇:UTF-8!
- DTD 的選擇:Strict!
- Super Pitch Gorugo
- 關於 Hinet 與 Xuite 信箱設定
- 關於 MagpieRSS
- 剛申請了 Google AdSense
- 關於 MySQL 的 TIMESTAMP 格式
- RSS 與 ATOM 各版本比對
-
▼
December
(23)
個人常用鏈結
Labels
- .NET (1)
- Accessibility (3)
- ADSL (1)
- Apache (9)
- ASP.NET (1)
- Babyer (1)
- Browser (1)
- Canon MX700 (1)
- CAPTCHA (1)
- CentOS (1)
- CSS (7)
- DB:SQL (1)
- DB:SQLite (2)
- DNS (3)
- English (1)
- EXIF (1)
- filename.ext (1)
- Firefox (4)
- Firewall (1)
- Flash (4)
- Game 遊戲 (28)
- Game:PC (6)
- Game:PS3 (4)
- Game:Xbox360 (3)
- GNU (1)
- Google (6)
- Google:Android (8)
- Google:Blogger (2)
- Google:Chrome (1)
- Google:Code (2)
- GoogleAppEngine (2)
- GoogleMaps (1)
- GPG (1)
- Hinet (1)
- HTML (2)
- HTTP (1)
- i18n (1)
- IE (3)
- Java (2)
- Javascript (2)
- Linux (1)
- Microsoft (2)
- MIME (1)
- MySQL (7)
- NexusOne (2)
- OAuth (1)
- Open source 開放原始碼 (1)
- OpenID (1)
- OS (1)
- OS:Windows (33)
- PHP (49)
- PHP:GTK (2)
- PHP:PEAR (1)
- PHP:PECL (3)
- PHP:ZendFramework (4)
- PostgreSQL (1)
- PPPoE (1)
- RegularExpressions (2)
- Security (11)
- Sphinx (2)
- SQLite (1)
- TCP (1)
- Ubuntu (1)
- UDP (1)
- Usability (2)
- Virtaul PC (1)
- Wii (2)
- XML (1)
- Yahoo (2)
- Yahoo:BBAuth (1)
- Yahoo:YUI (1)
- Youtube (1)
- 不如賣雞排 (2)
- 不願役 (33)
- 中文處理 (1)
- 圖 (5)
- 媒體 (2)
- 影片 (1)
- 影音 (19)
- 思 (8)
- 攝 (9)
- 政 (7)
- 敗 (2)
- 漫畫 (5)
- 生活 (34)
- 硬體設備 (13)
- 網站開發 (16)
- 網路 (8)
- 英文 (3)
- 貓 (2)
- 資安 (1)
- 趣 (29)
- 軟體 (12)
- 遊記 (8)
- 運動 (2)
- 關於我 (1)
- 電影 (10)
No comments:
Post a Comment
Comment Form Message