Recommendation: PHP-Curl multithreading tutorial

Source: Internet
Author: User
Reference this article is a demo of phpcurl multi-thread collection, which shows such features as much as possible. This demo environment is a local machine, so the performance cannot reach the maximum. It is only used as a description. for high performance, please go to the server for debugging. Select www.1ting.com as the target site, which is typical and fast in China. This article uses two classes (

Reference this article is a demo of php curl multi-thread collection, which shows such features as much as possible. This demo environment is a local machine, so the performance cannot reach the maximum. It is only used as a description. for high performance, please go to the server for debugging. Select http://www.1ting.com/as the target site. This site is relatively fast and fast. This article uses two classes (

Reference

This article is a demo of php curl multi-thread collection, which shows such features as much as possible. This demo environment is a local machine, so the performance cannot reach the maximum. It is only used as a description. for high performance, please go to the server for debugging. Select http://www.1ting.com/as the target site. This site is relatively fast and fast.

This article uses two classes (these two classes are included in the complete demo package ):
CUrl: multithreading, which can be found here.
PHPQuery: HTML analysis. The project address is http://code.google.com/p/phpquery /. If google is blocked, there is a newer version of phpQuery-0.9.5.386.zip. The single file class phpQuery/phpQuery. php In the compressed package is used here. It doesn't matter if you don't use this class. You can also use regular expression analysis.

The necessary file inclusion and initialization instance code are omitted.
The code is complete and can be run directly. Run the demo in command line mode (You know ).
The code is very concise...
PHPQuery requires php-dom extension, and installation is required if the PHP environment is not available. In addition, you must pay attention to this Article 1.1! If you use phpQuery, you must manually call phpQuery: unloadDocuments (); In the callback function. Otherwise, all documents processed by phpQuery are in the memory !!!
PDO is also required for database operations.
Since it is a demo, I will simplify everything on the program.
PhpQuery is very NB-intensive. Let's study a lot of abnormal usage. It can basically be said that it is omnipotent. If you use phpQuery, you must manually call phpQuery: unloadDocuments (); In the callback function. Otherwise, all documents processed by phpQuery are in the memory !!!
You can view the concurrency in connection viewer 360.

Some necessary content of CUrl:

Cache can be used for both single-line and multi-thread CUrl types, and the cache mechanism is the same.
The CUrl class captures the same structure of HTML single-line and multi-thread returned content.
$ Result = array ('info' => array (), 'content' => ");
$ Result ['info'] is the content of curl_info (), and $ result ['content'] is the captured html file.
Curl configuration is divided into three levels. The priority levels are as follows.
Default Value: As shown in the private method init.
Class Level: saved in the $ opt public attribute. All operations on this CURL object take effect.
Task level: this parameter is specified when a task is added to a multi-threaded task. It only applies to the current task.
Call_user_func_array () is used for callback functions in the class. Therefore, you must first understand this function in the PHP manual.



View Original article: PHP-Curl multithreading tutorial
Php curl Multithreading

Original article address: Recommended: PHP-Curl multi-thread tutorial. Thank you for sharing it with the original author.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.