Create your own PHP extension (on Windows)

Have you ever thought about writing your own PHP extension? There are surely a few pro’s and con’s about creating PHP extensions to solve problems, rather than write PHP libraries. But this is not the question here. I was curious. So come on Internet, let’s see what you got for me…

http://www.dreamincode.net/forums/topic/244215-introduction-to-creating-a-php-extension-for-windows/

http://blog.slickedit.com/2007/09/creating-a-php-5-extension-with-visual-c-2005/comment-page-2/

Looks a bit outdated, but that’s not the problem here for me. As a matter of fact, I’m currently still using PHP 5.3.5 on my dev for a list of reasons. And I’m using Windows and I don’t complain (I know my colleagues think I’m weird). Luckily both tutorials cover the topic on how to create the extension on Windows for PHP 5.3.5. So much win! And the best: it really works!

Basically both tutorials provide you with everything you need. I had to get over two pitfalls though:

  1. php5ts.lib is not in the source code directory I just extracted, but in my WAMP stack already – in my case I located it in C:\xampp\php\dev
  2. error C2371: ‘socklen_t’ : redefinition; different basic types¬†– I really have no idea why this error came up during compilation. However I was able to “solve” *cough* the problem by commenting out lines 149 to 151 in the php.h:
    #ifndef HAVE_SOCKLEN_T
    typedef unsigned int socklen_t;
    #endif
    

    Surely not the ideal solution, but as I just wanted to try it out I don’t mind at the moment.

Leave a Reply

Your email address will not be published. Required fields are marked *