Building Direct IO library for PHP with Mac Ports
Say you’re developing on a Mac, and want to test some PHP code that has calls to the direct IO library. You may not actually have a physical serial port, but your unit tests will fail in the wrong way if the library isn’t present. You want the unit tests to fail in the right way!
If you do the expected thing, you’ll find that dio is currently beta:
root# pecl install dio
Failed to download pecl/dio within preferred state "stable", latest release is version 0.0.5, stability "beta", use "channel://pecl.php.net/dio-0.0.5" to install
install failed
So you have to try to do it the hard way:
samuel:~ root# pecl install channel://pecl.php.net/dio-0.0.5
downloading dio-0.0.5.tgz ...
Easy-peasy, eh? Not so fast!
/private/tmp/pear/temp/dio/dio.c: In function 'zif_dio_fdopen':
/private/tmp/pear/temp/dio/dio.c:138: error: 'EBADFD' undeclared (first use in this function)
/private/tmp/pear/temp/dio/dio.c:138: error: (Each undeclared identifier is reported only once
/private/tmp/pear/temp/dio/dio.c:138: error: for each function it appears in.)
make: *** [dio.lo] Error 1
ERROR: `make' failed
Fortunately, via this bug report, we can see what to do:
# pecl download channel://pecl.php.net/dio-0.0.5
# tar xzvf dio-0.0.5.tgz
# cd dio-0.0.5
# phpize
# ./configure
Then edit dio.c, and change line 138 to:
if ((fcntl(fd, F_GETFL, 0) == -1) && (errno == EBADF)) {
Then, finish up:
# make
# make install
Then, create a file called “dio.ini” in /opt/local/var/db/php5/ containing:
extension=dio.so
Now you can run your tests!