Viking is an expensive operation. In appearance, what you really want is multi threading , not multi processing . The difference is that threads are much lighter than processes, because threads share a virtual address space, but processes have separate virtual address spaces.
I am not a PHP developer, but a quick Google search shows that PHP does not support multithreading, but there are libraries to do this work.
In any case, once you figure out how to create threads, you should find out how many threads will be created. To do this, you need to know what is the bottleneck of your application. Is CPU, memory, or I / O bottleneck? You indicated in your comments that you are attached to a network, and the network is an I / O type.
If you were associated with a processor, you only get parallelism, since you have processor cores; more threads, and you just spend time doing context switches. Assuming that you can figure out how many complete threads will be created, you should divide your work into many units and each thread processes one block independently.
If you were connected with memory, multithreading would not help.
Since you are involved with I / O, figuring out how many threads to spawn is a bit more complicated. If all work items take about the same time to process with very low dispersion, you can estimate how many threads will be created by measuring how much time one work item takes. However, since network packets tend to have very varying latencies, this is unlikely to occur.
One option is to use thread pools — you create an entire thread chain, and then for each item you process, you see if there is a free thread in the pool. If there is, you have this thread doing the work, and you move on to the next element. Otherwise, you wait until the stream becomes available. Choosing a thread pool size is important - too large, and you are wasting time on unnecessary context switches. Too few and you too often wait for threads.
Another option is to abandon multithreading / multiprocessing and instead do asynchronous I / O. Since you mentioned that you are working on a single-core processor, this is likely to be the fastest option. You can use functions like socket_select() to check if the socket has data. If so, you can read the data, otherwise you will switch to another socket. This requires much more accounting, but you do not expect the data to arrive on one socket, when the data is available on another socket.
If you want to avoid threads and asynchronous I / O and stick to multiprocessing, this can be useful if handling each item is expensive enough. Then you can make such a work unit:
$my_process_index = 0; $pids = array(); // Fork off $max_procs processes for($i = 0; $i < $max_procs - 1; $i++) { $pid = pcntl_fork(); if($pid == -1) { die("couldn't fork()"); } elseif($pid > 0) { // parent $my_process_index++; $pids[] = $pid } else { // child break; } } // $my_process_index is now an integer in the range [0, $max_procs), unique among all the processes // Each process will now process 1/$max_procs of the items for($i = $my_process_index; $i < length($items); $i += $max_procs) { do_stuff_with($items[$i]); } if($my_process_index != 0) { exit(0); }