The way to set the CPU affinity is with the sched_setaffinity
C function. It's not available through the standard PHP API so you probably would have to write an extension.
An alternative is running taskset
program through system
. For example this binds the PHP process to cores 0 and 1:
system('taskset -cp 0,1 '.getmypid());