Rumah > pembangunan bahagian belakang > tutorial php > 使用php-simple-html-dom-parser遇到的问题

使用php-simple-html-dom-parser遇到的问题

WBOY
Lepaskan: 2016-08-08 09:29:36
asal
1572 orang telah melayarinya

今天使用这个工具:

https://github.com/sunra/php-simple-html-dom-parser

遇到了问题,首先我是用了php-simple-html-dom-parser自带的testcase中的slick_test.php,就报错,然后我自己写了三行最简单的代码来抓一下百度首页:

<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>
Salin selepas log masuk

结果报错为:

<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&regType=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>
Salin selepas log masuk

这个报错:

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文件中可以看到这种错误日志:

<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>
Salin selepas log masuk

好吧,我们知道了无法连接到localhost:9000的socket端口,肯定的呀,因为我本地没有打开MacGDBP,这个是php的一个调试工具,如果你在php.ini的xdebug这里:

<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>
Salin selepas log masuk

如果xdebug.remote_autostart设置为1,也就是自动开启的话,就会直接请求开启9000端口的socket连接,如果没有就报错。原因就是这样:-)。

好了,因为这个日志文件输出还挺大的,所以我们可以关闭xdebug.remote_log了,也就是:

<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>
Salin selepas log masuk

加分号就ok了。

以上就介绍了使用php-simple-html-dom-parser遇到的问题,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

Label berkaitan:
sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan