51

Could any one tell me how to enable SOCKET support in PHP ?

Touki
  • 7,465
  • 3
  • 41
  • 63
Fero
  • 12,969
  • 46
  • 116
  • 157

5 Answers5

66

This answer assumes you do have a php_sockets.dll extension file accessible (in your PHP installation extension directory or where required);

If you're using windows, just uncomment the following line in your php.ini file:

;extension=php_sockets.dll

If you are missing the php_sockets.dll, you can download it from php.net.

nyedidikeke
  • 6,899
  • 7
  • 44
  • 59
Sampson
  • 265,109
  • 74
  • 539
  • 565
  • 2
    I have a linux godadday machine running a website. How do I enable socket programming there? – user1051505 Jan 11 '13 at 12:56
  • 2
    @user1051505 You might find [this discussion](http://support.godaddy.com/groups/web-hosting/forum/topic/php-sockets/?pc_split_value=2) in the GoDaddy forums to be helpful. – Sampson Jan 11 '13 at 15:46
  • I'm using XAMPP and I was getting `"Call to undefined function socket_create()..."` error. Although I have the `php_sockets.dll` file, `extension=php_sockets.dll` was not added to the `php.ini`. I had to add it manually. Now, it's working. – akinuri Apr 09 '18 at 06:53
  • 3
    in xampp server , its ;extension=sockets. this helped. – adeel ahmad Jun 07 '20 at 07:02
49

The PHP Docker images come with 3 helper script commands that make installing and configuring extensions easier:

  • docker-php-ext-configure: This command allows you to provide the custom arguments for an extension.
  • docker-php-ext-install: Use this command to install new extensions in your container.
  • docker-php-ext-enable: This command can be used to enable PHP extensions.

Run

docker-php-ext-install sockets

Reference: https://confluence.atlassian.com/bitbucket/php-with-bitbucket-pipelines-873907835.html#PHPwithBitbucketPipelines-InstallandenablePHPextensions

Codler
  • 10,951
  • 6
  • 52
  • 65
  • 3
    this is the correct answer if youre using docker – AaronHS Jan 08 '21 at 02:55
  • 1
    This showing a lot of errors. _/usr/src/php/ext/sockets/sendrecvmsg.c:128:19: error: invalid application of 'sizeof'_, _/usr/src/php/ext/sockets/sendrecvmsg.c:129:36: error: 'SCM_CREDS' undeclared_, And in the end: _make: *** [Makefile:213: sendrecvmsg.lo] Error 1_ (PHP 8.1 x64) – vee Jan 22 '22 at 13:59
16

here are noobs instructions

  • go to your php installation directory in windows it can be something like this c:\xampp\php

  • the go to ext directory in php\ext\

  • check if your have php_sockets.dll in that directory

  • after that open php.ini file which will be in your php folder

  • next search for ;extension=php_sockets.dll

if you find it then remove ; from it

if you not find it then search for extension=

and then below some extension add extension=php_sockets.dll

  • and finally restart your apache service.
user889030
  • 4,353
  • 3
  • 48
  • 51
  • 4
    in xampp latest version you will found ;extension=sockets not this ;extension=php_sockets.dll so you need to remove ; from ;extension=sockets and restart your apache. – Atul Baldaniya Jun 08 '21 at 06:04
8

For those of you that having this problem when installing RabbitMQ php library

Problem 1

  • Installation request for php-amqplib/php-amqplib ^2.11 -> satisfiable by php- amqplib/php-amqplib[v2.11.0].
  • php-amqplib/php-amqplib v2.11.0 requires ext-sockets * -> the requested PHP extension sockets is missing from your system.

Solution

change ;extension=sockets to extension=sockets over php.init

Screenshot

Notes:

Not sockets.dll, only sockets

David García Bodego
  • 1,058
  • 3
  • 13
  • 21
LAW WEI LIANG
  • 517
  • 5
  • 11
3

The socket functions described here are part of an extension to PHP which must be enabled at compile time by giving the --enable-sockets option to configure.

From the extension's documentation.

soulmerge
  • 73,842
  • 19
  • 118
  • 155