今天使用這個工具:
https://github.com/sunra/php-simple-html-dom-parser
遇到了問題,首先我是用了php-simple-html-dom-parser內建的testcase中的slick_test.php,就報錯,然後我自己寫了三行最簡單的代碼來抓一下百度首頁:
require'./simplehtmldom_1_5/simple_html_dom.php';$html = file_get_html('http://www.baidu.com/');//找到所有圖片 foreach($html->find('img') as$element) echo$element->src . '
'; //找到所有連結 foreach($html->find('a') as$element) echo$element->href . '
';
結果報錯為:
andy@AndyMacBookPro:/usr/local/webdata/github/php-simple-html-dom-parser/Src/Sunra/PhpSimple$ php andy.php//www.baidu.com/img/baidu_jgylogo3.gif
//www.baidu.com/img/bd_logo.png
http://s1.bdstatic.com/r/www/cache/static/global/img/gs_237f015b.gif
//www.baidu.com/gaoji/preferences.html
/
https://passport.baidu.com/v2/?login&tpl=mn&u=http%3A%2F%2Fwww.baidu.com%2F
https://passport.baidu.com/v2/?reg®Type=1&tpl=mn&u=http%3A%2F%2Fwww.baidu.com%2F
/
http://news.baidu.com/ns?cl=2&rn=20&tn=news&word=
http://tieba.baidu.com/f?kw=&fr=wwwt
http://zhidao.baidu.com/q?ct=17&pn=0&tn=ikaslist&rn=10&word=&fr=wwwt
http://music.baidu.com/search?fr=ps&key=
http://image.baidu.com/i?tn=baiduimage&ps=1&ct=201326592&lm=-1&cl=2&nc=1&word=
http://v.baidu.com/v?ct=301989888&rn=20&pn=0&db=0&s=25&word=
http://map.baidu.com/m?word=&fr=ps01000
http://wenku.baidu.com/search?word=&lm=0&od=0
//www.baidu.com/more/
javascript:;
javascript:;
javascript:;
http://w.x.baidu.com/go/mini/8/10000020
http://news.baidu.com
http://www.hao123.com
http://map.baidu.com
http://v.baidu.com
http://tieba.baidu.com
https://passport.baidu.com/v2/?login&tpl=mn&u=http%3A%2F%2Fwww.baidu.com%2F
//www.baidu.com/gaoji/preferences.html
//www.baidu.com/more/
http://news.baidu.com
http://tieba.baidu.com
http://zhidao.baidu.com
http://music.baidu.com
http://image.baidu.com
http://v.baidu.com
http://map.baidu.com
javascript:;
javascript:;
javascript:;
http://baike.baidu.com
http://wenku.baidu.com
http://www.hao123.com
//www.baidu.com/more/
/
//www.baidu.com/cache/sethelp/index.html
http://home.baidu.com
http://ir.baidu.com
/duty/
create_debugger_socket("localhost", 9000) socket: Too many open filescreate_debugger_socket("localhost", 9000) socket: Too many openfilescreate_debugger_socket("localhost", 9000) socket: Too many openfilescreate_debugger_socket("localhost", 9000) socket: Too many openfilescreate_debugger_socket("localhost", 9000) socket: Too many openfilescreate_debugger_socket("localhost", 9000) socket: Too many openfilescreate_debugger_socket("localhost", 9000) socket: Too many openfilescreate_debugger_socket("localhost", 9000) socket: Too many openfilescreate_debugger_socket("localhost", 9000) socket: Too many openfilescreate_debugger_socket("localhost", 9000) socket: Too many openfilescreate_debugger_socket("localhost", 9000) socket: Too many openfilescreate_debugger_socket("localhost", 9000) socket: Too many openfilescreate_debugger_socket("localhost", 9000) socket: Too many openfilescreate_debugger_socket("localhost", 9000) socket: Too many openfilescreate_debugger_socket("localhost", 9000) socket: Too many openfilescreate_debugger_socket("localhost", 9000) socket: Too many openfilescreate_debugger_socket("localhost", 9000) socket: Too many openfilescreate_debugger_socket("localhost", 9000) socket: Too many openfilescreate_debugger_socket("localhost", 9000) socket: Too many openfilescreate_debugger_socket("localhost", 9000) socket: Too many openfilesandy@AndyMacBookPro:/usr/local/webdata/github/php-simple-html-dom-parser/Src/Sunra/PhpSimple$
這個報錯:
create_debugger_socket(“localhost”, 9000) socket: Too many open files
搞不懂,不知道哪裡用到了socket串連??
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
現在搞定了,是這樣的,首先我想調試一下出錯的php看看哪裡的問題,然後我開啟了MacGDBP,發現開啟了MacGDBp之後,竟然不報錯了,又聯想到了9000連接埠,這個是xdebug的對應調試連接埠,所以有了一點思路,可能是xdebug的問題,然後在網上參考了這裡:
http://bugs.xdebug.org/view.php?id=1070
看到這裡:
- Installed Xdebug, and set xdebug.remote_connect_back and xdebug.remote_enable to 1 so that it connects to my host, running (or not running phpstorm)
- Set xdebug.remote_log=/tmp/remote.log
然後我們到/etc/php.ini中為xdebug的配置添加了
xdebug.remote_log = /tmp/xdebug_remote.log
之後我們繼續運行,繼續出錯,不過我們可以到/tmp/xdebug_remote.log檔案中可以看到這種錯誤記錄檔:
16 Log opened at2015-02-2003:48:2917 I: Connecting to configured address/port: localhost:9000.18 E: Could not connect to client. :-( 19 Log closed at2015-02-2003:48:29
好吧,我們知道了無法串連到localhost:9000的socket連接埠,肯定的呀,因為我本地沒有開啟MacGDBP,這個是php的一個調試工具,如果你在php.ini的xdebug這裡:
xdebug.remote_enable = onxdebug.remote_handler = dbgpxdebug.remote_host = localhostxdebug.remote_port = 9000xdebug.remote_autostart = 1
如果xdebug.remote_autostart設定為1,也就是自動開啟的話,就會直接請求開啟9000連接埠的socket串連,如果沒有就報錯。原因就是這樣:-)。
好了,因為這個記錄檔輸出還挺大的,所以我們可以關閉xdebug.remote_log了,也就是:
xdebug.remote_enable = onxdebug.remote_handler = dbgpxdebug.remote_host = localhostxdebug.remote_port = 9000xdebug.remote_autostart = 1;xdebug.remote_log = /tmp/xdebug_remote.log
加分號就ok了。
以上就介紹了使用php-simple-html-dom-parser遇到的問題,包括了方面的內容,希望對PHP教程有興趣的朋友有所協助。