2

I have a hash checker that works with cURL. it simply checks some hashes with an API. the API is fast but can I make it even faster by multithreading?

Here is my current code. It's current speed is 1-2 hashes per second. I really want it to do more than that.

<?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;
}
?>
Matt
  • 1,087
  • 1
  • 12
  • 28
  • 2
    The answer should be `curl_multi_exec()`, but you are using some kind of object layer around the curl functions that may not support it. Next best bet: Use [Guzzle 5](https://packagist.org/packages/guzzlehttp/guzzle) for parallel HTTP request execution. – Sven Jul 18 '15 at 00:10
  • I can switch to the normal php cURL but could you please explain how I would incorporate that? – Matt Jul 18 '15 at 00:13
  • 1
    https://www.google.de/search?q=php+curl_multi_exec+example – Sven Jul 18 '15 at 00:15
  • 1
    possible duplicate of [understanding php curl\_multi\_exec](http://stackoverflow.com/questions/15559157/understanding-php-curl-multi-exec) – Sven Jul 18 '15 at 00:16
  • Multithreading won't make it any faster. It would allow your script to do other things while waiting for the response, but is there anything your script can usefully do during that time? – Barmar Jul 18 '15 at 00:21

0 Answers0