How to Enable Socket Support In PHP

By | December 6, 2008

In order to add socket support with PHP you need just to include it into your configure string: there is no need to install any third-party applications or software. All you need is to recompile PHP, and it can be done in some minutes.

First of all you need to know where your PHP installation is located. I think you already have it installed if you are going to add some functions. Try searching for your PHP package (I mean installing PHP from source in this article) at your server: it should exist.

When you have the package near and know where it is located, you should identify your current configuration to avoid deleting some elements from the configure line. The most useful method is to copy your current configure line from the output produced by phpinfo(); You may create a new file containing just these lines:


Then run it using a web browser. At the beginning of this output you should see a configure line: it should look like:

'./configure' '--with-apxs2' '--with-curl=/usr/local/lib' '--with-gd' '--enable-gd-native-ttf' '--with-ttf' '--with-gettext' '--with-jpeg-dir=/usr/local/lib' '--with-freetype-dir=/usr/local/lib' '--with-kerberos' '--with-openssl' '--with-mcrypt' '--with-mhash' '--with-mysql=/usr' '--with-mysqli=/usr/bin/mysql_config' '--with-pear' '--with-png-dir=/usr/local/lib' '--with-zlib' '--with-zlib-dir=/usr/local/lib' '--enable-zip' '--with-iconv=/usr/local' '--enable-bcmath' '--enable-calendar' '--enable-ftp' '--enable-magic-quotes' '--enable-mbstring' '--enable-pcntl'

Copy it to your text editor and remove quotes and apostrophes. Then add ‘–enable-sockets’ to this line: that’s the only string we need to enable socket support.

Then we need to make PHP. If you’re doing it for the first time, see my previous post: How to configure PHP .

The command is simple enough: make :).


I’d suggest you to make clean before doing make to avoid some possible errors. After the PHP is  “made” you need to make install and then to reboot Apache or any web server you might have to see the changes. 

make clean;
make install;
service httpd restart;

If everything went OK, you should see that socket functions are now available.

2 thoughts on “How to Enable Socket Support In PHP

  1. admin Post author

    > Can you please help me and explain me how I should do what with
    > “Then we need to make PHP. The command is simple enough: make :).”.

    Please, let me know whether you have Directadmin or not. Also it is
    necessary to check whether you have PHP compiled from sources, but not
    an RPM build. To do this, you need to type rpm -qa | grep php. If this
    returns nothing, then you should download the latest PHP version from
    the website, unpack it and run the configure string. If it
    returns no errors, you should type make to the command line and hit
    return. This will compile your PHP. After doing make you should make
    install (that’s the command too). If everything goes OK, you should
    restart Apache (service httpd restart usually does the job).

  2. Pingback: Benny Design | WebSockets mit PHP

Comments are closed.