fogbound.net




Wed, 13 Jun 2012

Building Direct IO library for PHP with Mac Ports

— SjG @ 11:47 am

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!


2 responses to “Building Direct IO library for PHP with Mac Ports”

  1. Vasudevan says:

    Sir, I did everything as you mentioned. However, i am not able to run ‘make’ in fedora. It gives the same error.

    /tmp/dio-0.0.5/dio.c:99:58: error: ‘struct _php_core_globals’ has no member named ‘safe_mode’
    /tmp/dio-0.0.5/dio.c:99:105: error: ‘CHECKUID_CHECK_MODE_PARAM’ undeclared (first use in this function)
    /tmp/dio-0.0.5/dio.c:99:105: note: each undeclared identifier is reported only once for each function it appears in
    make: *** [dio.lo] Error 1

    could u please help me.

  2. SjG says:

    I’m afraid I haven’t tried this on Fedora. It looks to me like a PHP version incompatibility. Hasn’t “safe mode” been deprecated in modern PHP?

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.