How to get PHP script use more CPU for simple looping task? -
i have simple script tries 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 around 8 million iterations during 25 second window. during run cpu usage stays @ 0-1%. i'm running on 4 cores @ 3.8ghz. how can utilize cpu more php?
if did java or c++ instantly eat whole cpu while (1) loop , iteration count boost lot php.
ps. know finding collision impropable fun.
how can utilize cpu more php?
you try multi-threading approach using pthreads
from documentation:
pthreads object orientated api allows user-land multi-threading in php. includes tools need create multi-threaded applications targeted @ web or console. php applications can create, read, write, execute , synchronize threads, workers , stackables.
Comments
Post a Comment