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:
- Installed
- xdebug.remote_log = /tmp/xdebug_remote.log was added to /php.ini for the xdebug configuration. After that, we continued to run and errors continued, but we can see this in the /tmp/xdebug_remote.log file. Error 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>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.

Reasons for PHPSession failure include configuration errors, cookie issues, and session expiration. 1. Configuration error: Check and set the correct session.save_path. 2.Cookie problem: Make sure the cookie is set correctly. 3.Session expires: Adjust session.gc_maxlifetime value to extend session time.

Methods to debug session problems in PHP include: 1. Check whether the session is started correctly; 2. Verify the delivery of the session ID; 3. Check the storage and reading of session data; 4. Check the server configuration. By outputting session ID and data, viewing session file content, etc., you can effectively diagnose and solve session-related problems.

Multiple calls to session_start() will result in warning messages and possible data overwrites. 1) PHP will issue a warning, prompting that the session has been started. 2) It may cause unexpected overwriting of session data. 3) Use session_status() to check the session status to avoid repeated calls.

Configuring the session lifecycle in PHP can be achieved by setting session.gc_maxlifetime and session.cookie_lifetime. 1) session.gc_maxlifetime controls the survival time of server-side session data, 2) session.cookie_lifetime controls the life cycle of client cookies. When set to 0, the cookie expires when the browser is closed.

The main advantages of using database storage sessions include persistence, scalability, and security. 1. Persistence: Even if the server restarts, the session data can remain unchanged. 2. Scalability: Applicable to distributed systems, ensuring that session data is synchronized between multiple servers. 3. Security: The database provides encrypted storage to protect sensitive information.

Implementing custom session processing in PHP can be done by implementing the SessionHandlerInterface interface. The specific steps include: 1) Creating a class that implements SessionHandlerInterface, such as CustomSessionHandler; 2) Rewriting methods in the interface (such as open, close, read, write, destroy, gc) to define the life cycle and storage method of session data; 3) Register a custom session processor in a PHP script and start the session. This allows data to be stored in media such as MySQL and Redis to improve performance, security and scalability.

SessionID is a mechanism used in web applications to track user session status. 1. It is a randomly generated string used to maintain user's identity information during multiple interactions between the user and the server. 2. The server generates and sends it to the client through cookies or URL parameters to help identify and associate these requests in multiple requests of the user. 3. Generation usually uses random algorithms to ensure uniqueness and unpredictability. 4. In actual development, in-memory databases such as Redis can be used to store session data to improve performance and security.

Managing sessions in stateless environments such as APIs can be achieved by using JWT or cookies. 1. JWT is suitable for statelessness and scalability, but it is large in size when it comes to big data. 2.Cookies are more traditional and easy to implement, but they need to be configured with caution to ensure security.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 Linux new version
SublimeText3 Linux latest version
