Home > Article > Backend Development > Problems encountered when using php-simple-html-dom-parser
I used this tool today:
https://github.com/sunra/php-simple-html-dom-parser
I encountered a problem. First, I used the built-in php-simple-html-dom-parser slick_test.php in the testcase reported an error, and then I wrote the simplest three lines of code to capture the Baidu homepage:
<code><span><span><?php</span><span>require</span><span>'./simplehtmldom_1_5/simple_html_dom.php'</span>; <span>$html</span> = file_get_html(<span>'http://www.baidu.com/'</span>); <span>//找到所有图片 </span><span>foreach</span>(<span>$html</span>->find(<span>'img'</span>) <span>as</span><span>$element</span>) <span>echo</span><span>$element</span>->src . <span>'<br>'</span>; <span>//找到所有链接 </span><span>foreach</span>(<span>$html</span>->find(<span>'a'</span>) <span>as</span><span>$element</span>) <span>echo</span><span>$element</span>->href . <span>'<br>'</span>;</span></span></code>
The result is:
<code>andy@AndyMacBookPro:/usr/<span>local</span>/webdata/github/php-simple-html-dom-parser/Src/Sunra/PhpSimple$ php andy.php<span> //www.baidu.com/img/baidu_jgylogo3.gif<br>//www.baidu.com/img/bd_logo.png<br>http://s1.bdstatic.com/r/www/cache/static/global/img/gs_237f015b.gif<br>//www.baidu.com/gaoji/preferences.html<br>/<br>https://passport.baidu.com/v2/?login&tpl=mn&u=http%3A%2F%2Fwww.baidu.com%2F<br>https://passport.baidu.com/v2/?reg®Type=1&tpl=mn&u=http%3A%2F%2Fwww.baidu.com%2F<br>/<br>http://news.baidu.com/ns?cl=2&rn=20&tn=news&word=<br>http://tieba.baidu.com/f?kw=&fr=wwwt<br>http://zhidao.baidu.com/q?ct=17&pn=0&tn=ikaslist&rn=10&word=&fr=wwwt<br>http://music.baidu.com/search?fr=ps&key=<br>http://image.baidu.com/i?tn=baiduimage&ps=1&ct=201326592&lm=-1&cl=2&nc=1&word=<br>http://v.baidu.com/v?ct=301989888&rn=20&pn=0&db=0&s=25&word=<br>http://map.baidu.com/m?word=&fr=ps01000<br>http://wenku.baidu.com/search?word=&lm=0&od=0<br>//www.baidu.com/more/<br>javascript:;<br>javascript:;<br>javascript:;<br>http://w.x.baidu.com/go/mini/8/10000020<br>http://news.baidu.com<br>http://www.hao123.com<br>http://map.baidu.com<br>http://v.baidu.com<br>http://tieba.baidu.com<br>https://passport.baidu.com/v2/?login&tpl=mn&u=http%3A%2F%2Fwww.baidu.com%2F<br>//www.baidu.com/gaoji/preferences.html<br>//www.baidu.com/more/<br>http://news.baidu.com<br>http://tieba.baidu.com<br>http://zhidao.baidu.com<br>http://music.baidu.com<br>http://image.baidu.com<br>http://v.baidu.com<br>http://map.baidu.com<br>javascript:;<br>javascript:;<br>javascript:;<br>http://baike.baidu.com<br>http://wenku.baidu.com<br>http://www.hao123.com<br>//www.baidu.com/more/<br>/<br>//www.baidu.com/cache/sethelp/index.html<br>http://home.baidu.com<br>http://ir.baidu.com<br>/duty/<br>create_debugger_socket("localhost", 9000) socket: Too many open files</span> create_debugger_socket(<span>"localhost"</span>, <span>9000</span>) <span>socket</span>: Too many <span>open</span><span>files</span> create_debugger_socket(<span>"localhost"</span>, <span>9000</span>) <span>socket</span>: Too many <span>open</span><span>files</span> create_debugger_socket(<span>"localhost"</span>, <span>9000</span>) <span>socket</span>: Too many <span>open</span><span>files</span> create_debugger_socket(<span>"localhost"</span>, <span>9000</span>) <span>socket</span>: Too many <span>open</span><span>files</span> create_debugger_socket(<span>"localhost"</span>, <span>9000</span>) <span>socket</span>: Too many <span>open</span><span>files</span> create_debugger_socket(<span>"localhost"</span>, <span>9000</span>) <span>socket</span>: Too many <span>open</span><span>files</span> create_debugger_socket(<span>"localhost"</span>, <span>9000</span>) <span>socket</span>: Too many <span>open</span><span>files</span> create_debugger_socket(<span>"localhost"</span>, <span>9000</span>) <span>socket</span>: Too many <span>open</span><span>files</span> create_debugger_socket(<span>"localhost"</span>, <span>9000</span>) <span>socket</span>: Too many <span>open</span><span>files</span> create_debugger_socket(<span>"localhost"</span>, <span>9000</span>) <span>socket</span>: Too many <span>open</span><span>files</span> create_debugger_socket(<span>"localhost"</span>, <span>9000</span>) <span>socket</span>: Too many <span>open</span><span>files</span> create_debugger_socket(<span>"localhost"</span>, <span>9000</span>) <span>socket</span>: Too many <span>open</span><span>files</span> create_debugger_socket(<span>"localhost"</span>, <span>9000</span>) <span>socket</span>: Too many <span>open</span><span>files</span> create_debugger_socket(<span>"localhost"</span>, <span>9000</span>) <span>socket</span>: Too many <span>open</span><span>files</span> create_debugger_socket(<span>"localhost"</span>, <span>9000</span>) <span>socket</span>: Too many <span>open</span><span>files</span> create_debugger_socket(<span>"localhost"</span>, <span>9000</span>) <span>socket</span>: Too many <span>open</span><span>files</span> create_debugger_socket(<span>"localhost"</span>, <span>9000</span>) <span>socket</span>: Too many <span>open</span><span>files</span> create_debugger_socket(<span>"localhost"</span>, <span>9000</span>) <span>socket</span>: Too many <span>open</span><span>files</span> create_debugger_socket(<span>"localhost"</span>, <span>9000</span>) <span>socket</span>: Too many <span>open</span><span>files</span> andy@AndyMacBookPro:/usr/<span>local</span>/webdata/github/php-simple-html-dom-parser/Src/Sunra/PhpSimple$</code>
This error:
create_debugger_socket("localhost", 9000 ) socket: Too many open files
I don’t understand. I wonder where the socket connection is used? ?
%%%%%%%%%%%%%%%%%%%%%%%%%%%
Now it's done, like this, first I wanted to debug the php that went wrong to see what the problem was, then I turned on MacGDBP, and found that after turning on MacGDBp, no error was reported, and I thought of port 9000, which is the counterpart of xdebug Debug port, so I have some ideas, it may be a problem with xdebug, and then I referenced this online:
http://bugs.xdebug.org/view.php?id=1070
See here:
<code><span>16</span> Log opened <span>at</span><span>2015</span>-<span>02</span>-<span>20</span><span>03</span>:<span>48</span>:<span>29</span><span>17</span> I: Connecting <span>to</span> configured address/port: localhost:<span>9000.</span><span>18</span> E: Could <span>not</span> connect <span>to</span> client. :-( <span>19</span> Log closed <span>at</span><span>2015</span>-<span>02</span>-<span>20</span><span>03</span>:<span>48</span>:<span>29</span></code>Okay, we know that we cannot connect to the socket port of localhost:9000. Yes, because I have not opened MacGDBP locally. This is a debugging tool for php. If you are in xdebug of php.ini :
<code>xdebug<span>.remote</span>_enable = on xdebug<span>.remote</span>_handler = dbgp xdebug<span>.remote</span>_host = localhost xdebug<span>.remote</span>_port = <span>9000</span> xdebug<span>.remote</span>_autostart = <span>1</span></code>If xdebug.remote_autostart is set to 1, that is, if it is turned on automatically, it will directly request to open the socket connection of port 9000. If not, an error will be reported. That's why :-). Okay, because the output of this log file is quite large, we can turn off xdebug.remote_log, that is:
<code>xdebug.<span>remote_enable = on</span> xdebug.<span>remote_handler = dbgp</span> xdebug.<span>remote_host = localhost</span> xdebug.<span>remote_port = 9000</span> xdebug.<span>remote_autostart = 1</span> ;xdebug.<span>remote_log = /tmp/xdebug_remote.log</span></code>Add a semicolon and it will be ok.
The above introduces the problems encountered when using php-simple-html-dom-parser, including the content. I hope it will be helpful to friends who are interested in PHP tutorials.