Home PHP Libraries Other libraries PHP curl multi-thread collection class
PHP curl multi-thread collection class
<?php
<?php
set_time_limit(0);
$urls = array('http://www.baidu.com','http://www.php.cn',);
$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.

Disclaimer

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

PHP CURL multi-threaded GET/POST class PHP CURL multi-threaded GET/POST class

25 Jul 2016

PHP CURL multi-threaded GET/POST class

A guide to implementing PHP multi-threaded programming using the Thread class A guide to implementing PHP multi-threaded programming using the Thread class

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

Implementation code for PHP multi-thread batch collection and downloading of pictures of beautiful women_PHP tutorial Implementation code for PHP multi-thread batch collection and downloading of pictures of beautiful women_PHP tutorial

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

Implementation code for PHP multi-thread batch collection and downloading of pictures of beautiful women (continued)_PHP tutorial Implementation code for PHP multi-thread batch collection and downloading of pictures of beautiful women (continued)_PHP tutorial

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.

How Do I Link Static Libraries That Depend on Other Static Libraries? How Do I Link Static Libraries That Depend on Other Static Libraries?

13 Dec 2024

Linking Static Libraries to Other Static Libraries: A Comprehensive ApproachStatic libraries provide a convenient mechanism to package reusable...

How to import third-party libraries in ThinkPHP How to import third-party libraries in ThinkPHP

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/

See all articles