Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何使用curl进行多线程处理?_Php_Multithreading_Curl_Php 5.3 - Fatal编程技术网

Php 如何使用curl进行多线程处理?

Php 如何使用curl进行多线程处理?,php,multithreading,curl,php-5.3,Php,Multithreading,Curl,Php 5.3,我有一个用于cURL的哈希检查程序。它只是用API检查一些散列。API很快,但是我可以通过多线程使它更快吗 这是我目前的代码。它的当前速度是每秒1-2个哈希。我真的希望它能做得更多 <?php include_once("curl.php") ; $hashes = file_get_contents("hashes.txt"); $accs = explode("\n",$hashes); foreach($accs as $a){ $x = explode(":",$a); $c =

我有一个用于cURL的哈希检查程序。它只是用API检查一些散列。API很快,但是我可以通过多线程使它更快吗

这是我目前的代码。它的当前速度是每秒1-2个哈希。我真的希望它能做得更多

<?php
include_once("curl.php") ;
$hashes = file_get_contents("hashes.txt");
$accs = explode("\n",$hashes);
foreach($accs as $a){
$x = explode(":",$a);
$c = new curl("website.com");
$c->setopt(CURLOPT_FOLLOWLOCATION, true) ;
$c->setopt(CURLOPT_POST, true) ;
$c->setopt(CURLOPT_RETURNTRANSFER, true);
$c->setopt(CURLOPT_COOKIESESSION, 1);
$c->setopt(CURLOPT_COOKIEJAR, 'cookie.txt');
$c->setopt(CURLOPT_COOKIEFILE, 'cookie.txt');
$c->setopt(CURLOPT_POST, true);
$c->setopt(CURLOPT_POSTFIELDS, "hash0=".$x[0]."&verify=".$x[1]); 
$done = $c->exec();
echo $done;
}
?>


答案应该是
curl\u multi\u exec()
,但您在curl函数周围使用的对象层可能不支持它。下一个最佳选择:用于并行HTTP请求执行。我可以切换到普通的php cURL,但您能解释一下我将如何合并它吗?多线程的可能重复不会使它更快。它允许您的脚本在等待响应时执行其他操作,但在这段时间内,您的脚本有什么有用的操作吗?答案应该是
curl\u multi\u exec()
,但是您在curl函数周围使用了某种对象层,可能不支持它。下一个最佳选择:用于并行HTTP请求执行。我可以切换到普通的php cURL,但您能解释一下我将如何合并它吗?多线程的可能重复不会使它更快。它允许您的脚本在等待响应时执行其他操作,但在这段时间内,您的脚本是否可以有效地执行任何操作?