Thanks to visit codestin.com
Credit goes to github.com

Skip to content

A php extension which provides functions to modify CPU affinity

Notifications You must be signed in to change notification settings

luozy/php-affinity

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

php-affinity

A PHP extension which provides functions to modify CPU affinity

Introduce

Affinity extension provides three functions:

  • getaffinity get CPU number which current process is running in.
  • setaffinity change the process to another CPU
  • getcpucores get number of CPU cores

Install

tar zxvf affinity.tar.gz
cd affinity
phpize
./configure --with-php-config=/path/to/php-config
make && make test && make install

API

/**
 * set CPU affinity
 *
 * @param $cpu_id
 * @return bool
 */
function setaffinity($cpu_id){
    $num = getcpucores();
    if($cpu_id >= $num){
        return false;
    }
    $set = system_call($cpu_id);
    if($set === -1){
        return false;
    }

    return true;
}

/**
 * get CPU affinity
 *
 * @return bool
 */
function getaffinity(){
    $cpu_id = system_call();
    if($cpu_id === -1){
        return false;
    }
    return $cpu_id;
}


/**
 * get number of CPU
 *
 * @return bool
 */
function getcpucores(){
    $nums = system_call();
    if($nums === -1){
        return false;
    }
    return $nums;
}

About

A php extension which provides functions to modify CPU affinity

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C 78.3%
  • PHP 21.7%