<?php <?php set_time_limit(0); $urls = array('http://www.baidu.com','//m.sbmmt.com',); $handle = curl_multi_init(); $curls = array(); foreach ($urls as $k=>$url) { $curls[$k] = add_handle($handle, $url); } function add_handle(& $handle, $url) { $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_HEADER, ''); curl_setopt($curl,CURLOPT_USERAGENT,"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)"); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_multi_add_handle($handle, $curl); return $curl; }
This is a PHP curl multi-thread collection class. Friends who need it can download it and use it.
All resources on this site are contributed by netizens or reprinted by major download sites. Please check the integrity of the software yourself! All resources on this site are for learning reference only. Please do not use them for commercial purposes. Otherwise, you will be responsible for all consequences! If there is any infringement, please contact us to delete it. Contact information: admin@php.cn
Related Article
30 Jun 2023
Introductory Guide to PHP Multi-Threaded Programming: Using the Thread Class to Create Multi-Threaded Applications Introduction: With the development of the Internet, PHP, as a powerful scripting language, is widely used in Web development. However, since PHP is a single-threaded language, this can cause performance issues when handling a large number of concurrent requests. In order to solve this problem, we can achieve concurrent processing by using multi-threaded programming in PHP. This article will introduce how to use the Thread class to create multi-threaded applications. 1. Overview of multi-threaded programming Multi-threaded programming refers to
13 Jul 2016
Implementation code for PHP multi-threaded batch collection and downloading of pictures of beautiful women. Implementation code of PHP multi-threaded batch collection and downloading of beautiful girl pictures using curl's multi-threading. In addition, curl can set the request time. When encountering a very slow URL resource, you can give up decisively. This way there is no
21 Jul 2016
Implementation code for PHP multi-threaded batch collection and downloading of pictures of beautiful women (continued). Personally I think the reason for the impact: The matched image URL is not a valid URL. The article simply judges whether it is a relative path, but some URLs are invalid. Solution: Just add a new URL.
03 Jun 2023
Third-party class libraries Third-party class libraries refer to other class libraries besides the ThinkPHP framework and application project class libraries. They are generally provided by third-party systems or products, such as class libraries of Smarty, Zend and other systems. For the class libraries imported earlier using automatic loading or the import method, the ThinkPHP convention is to use .class.php as the suffix. Non-such suffixes need to be controlled through the import parameters. But for the third type of library, since there is no such agreement, its suffix can only be considered to be php. In order to easily introduce class libraries from other frameworks and systems, ThinkPHP specifically provides the function of importing third-party class libraries. Third-party class libraries are uniformly placed in the ThinkPHP system directory/
20 Jun 2017
When developing with jQuery, you may also use other JS libraries, such as Prototype, but conflicts may occur when multiple libraries coexist; if conflicts occur, you can solve them through the following solutions: 1. jQuery libraries in other Import the library before and use the jQuery (callback) method directly such as:
Hot Tools
PHP library for dependency injection containers
PHP library for dependency injection containers
A collection of 50 excellent classic PHP algorithms
Classic PHP algorithm, learn excellent ideas and expand your thinking
Small PHP library for optimizing images
Small PHP library for optimizing images