Monday, July 27, 2009

PHPhD – Server side hardware port access extension for PHP

In one of my project I need to access PC hardware ports using PHP. Standard distribution of PHP (PHP for Windows) may not have facilities to access PC/Server hardware ports, and finally I developed lightweight PHP extension to access server hardware ports.

Current version of PHPhD (version support for PHP 5.2.x (tested with PHP 5.2.1) and distributed under the terms and conditions of Mozilla Public License version 1.1. This PHP extension is available to download at

Using PHPhD users can access server hardware ports with minimum amount of coding and complexity. Example PHP source code which was based on PHPhD is listed in below,

//Initialize and open hardware device driver
if(!phphd_open_driver()) {
die("Unable to open PHP hardware port access device driver");

//read printer (LPT) port and get the curent port value
$lpt_port_val = phphd_read_port(0x378+1);
echo("LPT port value [0x378+1] : ".

//close device driver

Current version of PHPhD (version has following functions,

  • phphd_open_driver : Function to load device driver and initialize the hardware access session.
  • phphd_close_driver : Function to close current device driver and release all the hardware sessions.
  • phphd_isopen : Function to get the initialization status of the device driver.
  • phphd_read_port : Read specified hardware port and return the value.
  • phphd_write_port : Function to write value to the specified hardware port.
  • phphd_sound : Function to trigger the system (server) speaker with given frequency and period. Most of the times we use this function to test the device driver and functionality of PHPhD.

Please note that this PHP extension is available for the Windows platforms only.
Post a Comment