follow me on Twitter

    Latest Gallery Images

    PHP Women
    LinuxChix
    Blogs By Women
    Creative Commons Licence

    Archive for the ‘PHP’ Category

    Capturing still images from video devices in PHP using Framegrab

    Sunday, February 28th, 2010

    I found I had a need to capture and process still video images from video devices using PHP so I wrote the Framegrab PECL extension. This post introduces the basics of Framegrab.
    (more…)

    Serial IO in PHP using the DIO extension

    Monday, February 15th, 2010

    DIO is the Direct IO extension for PHP. I recently took over maintaining this extension and have implemented comprehensive stream support for both POSIX and Windows systems. To demonstrate the use of DIO this post will describe a PHP script that sends an SMS using a USB 3G modem.
    (more…)

    PHP DIO Extension: Looking for beta testers

    Tuesday, February 2nd, 2010

    A few months ago I had a need to do some serial IO from PHP. After asking around I found out there was a PHP extension for this but it was unmaintained, unowned and out of date. To cut a long story short I ended up as the maintainer of said extension and since them I have been fixing and extending it.

    The original DIO API is very basic and POSIX oriented. Serial support is not very configurable and doesn’t work at all on Window platforms. So I have been working on implementing PHP stream extensions that allow you to do raw and serial IO via streams. Anyway its ready for testing by people other than me on POSIX (Linux, OS X etc) and Windows platforms so I’m looking for beta testers.

    (more…)

    Building PHP C extensions on Ubuntu 9.10

    Tuesday, December 1st, 2009

    I have just taken over maintenance of the PECL Direct IO extension as it has been unmaintained for a while. Naturally the first thing I did before writing any new code was to check out the extension from SVN and try and build it. Building the source was fine but when I tried make test it failed producing output like the following:

    PHP Warning:  PHP Startup: Unable to load dynamic library 'modules/gd.so' -
    modules/gd.so: cannot open shared object file: No such file or
    directory in Unknown on line 0
    
    Warning: PHP Startup: Unable to load dynamic library 'modules/gd.so' -
    modules/gd.so: cannot open shared object file: No such file or
    directory in Unknown on line 0
    

    The default PHP package on Ubuntu 9.10 is fairly minimalist. Most extensions are provided as separate packages which include an INI file and a dynamic library. The dynamic library is stored in:

    /usr/lib/php5/20060613+lfs
    

    And the INI file for each extension is in:

    /etc/php5/conf.d.
    

    The make tests rule in the generated Makefile in the extension you are compiling modifies the path that PHP searches for extensions by to point to the modules directory within the extension source. So PHP, which is used to run the tests, cannot find the extensions.

    I’ve found the easiest way (if slightly hacky) to fix the make test failure is just to copy the .so files from the PHP5 extension directory in to the modules directory within the extension source.

    Installing eclipse for multiple programming languages

    Friday, November 20th, 2009

    I can do almost everything I need to do in OS X but just occasionally I need Linux. So I recently installed a VirtualBox VM running Ubuntu 9.10. I use Eclipse as my favoured IDE since I can run it on all three of the major OSes and it has good support for C, C++ and Java which is what I use mostly for work. So the next thing for me was to install Eclipse. This is where things became interesting.
    (more…)

    Boarduino vivarium temperature monitor

    Thursday, October 29th, 2009

    I like snakes. This weekend I will be collecting my new snake, he’s a baby Royal Python. I have been worried about the temperature in the vivarium I will be housing him so I built an ethernet enabled monitoring device to do a science!

    Vivarium Temperature Monitor

    (more…)

    PHP NW and the Decorator Pattern

    Wednesday, September 9th, 2009

    The first Tuesday of the month is the PHP NW meeting in Manchester. This month I was the warm act for PHP celebrity Derick Rethans. Due to traffic issues Lornajane and Derick were late so I gave my talk first. It was one in a series of talks on Design Patterns being given by various members of the group. Mine was on the Decorator Pattern. The slides from the talk are available for download.

    Derick’s very interesting talk was on Test Driven Development in a PHP environment. Derick is the author of XDebug and an expert in PHP QA. It covered the concepts behind Test Driven Development and why it both improves code quality and makes code development more efficient over the long term. It covered the use of PHPUnit, XDebug and CruiseControl. As a fan of quality reusable code this is a great way to develop.

    Next month is the PHP NW 2009 Conference held in Manchester. The you can see Derick and some of other great European PHP conference speakers doing their thing. Its fantastic value for money and you get a year’s subscription to PHP Architect Magazine too. Bargain!

    Talk: Introduction to Wordpress Plugins

    Wednesday, August 5th, 2009

    Last night I gave my first pukka pecha kucha talk at the monthly PHPNW. The talk is a lightning talk with 20 slides with 20 seconds a slide. I.e. 6 minutes 40 seconds in total. Since I hadn’t even decided I was going to talk until last Friday and I had no talk prepared I was still preparing the slides on the train to Manchester where the meetings are held.

    I didn’t have a VGA adapter for my MacBook and had to borrow one to connect it to the project. I think I need to buy one. I bought a DVI adapter when I bought the machine but not the VGA one as I thought who needs them with modern monitors. But of course most projectors have VGA only connections so such adapters are a necessary component of the presenter’s toolkit.

    The talk seemed to go well and was appreciated by the audience and plugins seemed to be my topic of conversation for the rest of the evening. There was some interest in my Wordpress Coppermine Widget plugin and techniques I had used in the Javascript for it. I think this will become the subject of another blog post.

    I went a little awry with my mental arithmetic and ran over by about a minute. When Lornajane gave her talk she had the slides change automatically after 20 seconds so you know when the talking time for a slide is up. I will steal this idea!

    My slides are available as a PDF download.

    Wordpress Automatic Update Bug – Follow Up

    Thursday, July 16th, 2009

    The bug I raised on Wordpress yesterday as documented in this blog post has been closed as a ‘duplicate’.

    Looking through the bugs about a month ago someone else raised a very similar bug report and proposed a very similar solution. That bug report was closed with ‘wontfix’. The basic comment is that (a) they know about it; (b) they think changing the behaviour will break shared hosting; (c) group write support is not supported in Wordpress anyway.

    The comments in the bug do confirm something I spotted yesterday when looking at the latest release revision of wp-admin/includes/file.php which is that you can completely over-ride the write checking mechanism in Wordpress 2.8 and above if you define the constant FS_METHOD to be ‘direct’. A bit hacky but useful. It means I can use decent permissions and still use auto-update. Time to upgrade to 2.8.1 I think.

    Wordpress Automatic Update Bug

    Wednesday, July 15th, 2009

    LornaJane wrote an article on her blog about Wordpress automatic update asking for FTP. As I’ve been having problems with the automatic update too and since I also don’t want to install FTP I changed permissions as she suggested. Unfortunately, even with ‘other’ (world) write permissions, I was still being asked for FTP details. After some discussion on IRC it turns out that not only do you need the right permissions but you need the files with the right owner i.e. the Apache process. This didn’t seem right. Why an earth do you need the right ownership if you can write anyway. Also if you have to have the files owned by the Apache process any scripting running on the server can access and change the files. Its a security risk. So I decided to dig deeper.

    Grepping the Wordpress source for the text line ‘There was an error connecting to the server, Please verify the settings are correct.’ showed me the relevant code is in wp-admin/includes/file.php. The function that requests the FTP details is request_filesystem_credentials(). This function is called if get_filesystem_method() returns a method other than ‘direct’. It seemed that get_filesystem_method() was at fault. The relevant code snippet is below.

            $method = false;
            if( function_exists('getmyuid') && function_exists('fileowner') ){
                    $temp_file = wp_tempnam();
                    if ( getmyuid() == fileowner($temp_file) )
                            $method = 'direct';
                    unlink($temp_file);
            }

    Examining the function it seems that it tries to creates temporary file (typically in wp-content) and if successful compares the ownership of that file with the process. If equivalent it decides that it can use ‘direct’ mode. The problem is it uses getmyuid() which according to the documentation returns the owner of the file that called the function and not the owner of the process running the code. I.e. the owner of wp-admin/includes/file.php. It doesn’t matter who the owner of the apache process is. There is another function
    posix_getuid() which returns the process owner. So I have modified the get_filesystem_method() function as follows:

            $method = false;
            if( function_exists('posix_getuid') && function_exists('fileowner') ){
                    $temp_file = wp_tempnam();
                    if ( posix_getuid() == fileowner($temp_file) )
                            $method = 'direct';
                    unlink($temp_file);
            } else if( function_exists('getmyuid') && function_exists('fileowner') ){
                    $temp_file = wp_tempnam();
                    if ( getmyuid() == fileowner($temp_file) )
                            $method = 'direct';
                    unlink($temp_file);
            }

    I.e it checks to see if posix_getuid() is supported and if it is it uses that instead. This allows me to have my Wordpress files owned by a different owner than the apache process. I have set the wp-content to a member of a group containing the apache process owner and made them group writeable. As long as apache can write the temp file Wordpress can use automatic update. This is still some what insecure but better than having all the Wordpress files either owner by the apache process or world writeable.

    Note that I am currently running Wordpress 2.7.1. Looking at Wordpress 2.8.1 the get_filesystem_method() function has changed but not significantly. I am raising a bug.