0

I have a simple script that tries to find MD5 collisions via brute force.

// Pseudo:
while (runtime < 25 seconds) {
  random_hash1 = random_hash();
  random_hash2 = random_hash();

  if (random_hash1 == random_hash2) {
    notify_user();
  }
}

It's working fine itself but I only get around 8 million iterations during this 25 second window. During the run my cpu usage stays at 0-1%. I'm running on 4 cores at 3.8ghz. How can I utilize my cpu more with PHP?

If I did this with java or c++ I would instantly eat whole CPU with my while (1) loop and the iteration count would boost up a lot but I would like to do this with PHP.

PS. I know finding collision is impropable but I do it for fun.

sleepless_in_seattle
  • 2,132
  • 4
  • 24
  • 35
  • 2
    I think you can try run it in parallel threads. Something like this: http://stackoverflow.com/questions/11747304/executing-multiple-php-scripts-in-parallel-and-being-notified-when-finished – stepozer Jun 14 '15 at 19:35

1 Answers1

0

How can I utilize my cpu more with PHP?

You could try a multi-threading approach using pthreads

From the documentation:

pthreads is an Object Orientated API that allows user-land multi-threading in PHP. It includes all the tools you need to create multi-threaded applications targeted at the Web or the Console. PHP applications can create, read, write, execute and synchronize with Threads, Workers and Stackables.