What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

Enable PHP’s sockets extension in the exact PHP installation and Server API (SAPI) used by your application, restart that long-running process, and verify the web runtime separately from the command line. On a source build, sockets must be compiled with --enable-sockets; on packaged Linux or Windows installations, activation depends on the active configuration file, extension files, and SAPI.

What PHP sockets is and why the function is undefined

PHP sockets is an extension that provides low-level networking functions such as socket_create(). It is part of PHP itself, not a Composer package or an application-level library. When PHP reports Call to undefined function socket_create(), the PHP process handling that request has not loaded the sockets extension.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The most common source of confusion is that a server can have several PHP runtimes at once. The command-line interpreter may load one php.ini, while Apache, PHP-FPM, CGI, or IIS FastCGI loads another. A successful command-line check therefore does not prove that a web request can call socket_create().

Use this order for every installation:

  1. Identify the PHP binary, version, configuration file, and SAPI used by the code.
  2. Check whether sockets is already loaded in that runtime.
  3. Enable it in the matching configuration or compile it into a source build.
  4. Restart the web server or PHP process that keeps configuration in memory.
  5. Verify the web SAPI with a temporary diagnostic page and a minimal function test.

Identify the PHP runtime before editing anything

Check the command-line PHP installation

From a shell, run:

command -v php
php -v
php --ini
php -m | grep -i sockets

command -v php shows which executable your shell resolves. php -v identifies its version and build details, and php --ini reports the configuration directory and the loaded php.ini path. The final command lists loaded modules and filters for sockets. If it prints sockets, the CLI interpreter has the extension; if it prints nothing, sockets is not loaded in that CLI process.

These commands describe only the CLI SAPI. They do not identify the configuration used by an Apache module, PHP-FPM pool, CGI process, or IIS FastCGI worker.

Find the web SAPI’s actual configuration

Create a temporary file in the document root containing:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
<?php
phpinfo();
?>

Open that page through the same hostname and web server path used by the application. In the output, locate Server API, PHP Version, Loaded Configuration File, Scan this dir for additional .ini files, and the list of loaded modules. The sockets section should appear when the extension is active.

Delete the file immediately after checking it. A phpinfo() page exposes detailed paths, build flags, environment values, and module information that should not remain publicly accessible.

Enable sockets on Debian- and Ubuntu-style systems

1. Confirm whether the module is already loaded

Run the CLI check:

php -m | grep -i sockets

If the result is sockets, do not enable a second copy. Instead, check the web SAPI with phpinfo(); the CLI and web process may still be using different PHP versions or configuration trees.

2. Enable the packaged module with the distribution helper

When the matching distribution package is installed but the module is disabled, Debian-family systems commonly use:

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
sudo phpenmod sockets

The helper creates or activates the appropriate configuration links for the installed PHP version and SAPI. It is preferable to editing a random global file because Debian organizes configuration by PHP version and SAPI. A typical layout uses directories such as /etc/php/M.N/cli/, /etc/php/M.N/apache2/, and /etc/php/M.N/fpm/, with additional module configuration in each SAPI’s conf.d directory.

The exact package name is distribution- and PHP-version-specific. Do not assume that a package name from another release or tutorial matches your system. Use the operating system’s package search to find the sockets module for the PHP stream that your application actually runs.

3. Restart the process that serves web requests

PHP reads configuration when a process starts. After enabling sockets, restart the relevant Apache service, PHP-FPM service, or other web SAPI process with the service manager used by your operating system. A CLI shell does not need to be restarted; a long-running web worker does.

For PHP-FPM, make sure you restart the pool corresponding to the PHP version serving the site. If a reverse proxy or process manager launches PHP separately, restart that managed process as well. Reloading only a front-end web server is not sufficient when the PHP workers themselves retain the old configuration.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

4. Verify the web configuration, not just the shell

Visit the temporary phpinfo() page again. Confirm all of the following:

  • The displayed PHP version is the one you intended to change.
  • Server API identifies the web SAPI you restarted.
  • Loaded Configuration File points to the file or configuration tree you edited or enabled.
  • A sockets section is present in the module list.

Then test the function directly with a temporary page:

<?php
var_export(function_exists('socket_create'));
?>

A result of true confirms that the current web request can resolve the function. Remove both diagnostic files when testing is complete.

When phpenmod cannot find sockets

If the helper reports that the module is unavailable, first compare the PHP version from php -v with the version shown by web phpinfo(). Then inspect the corresponding /etc/php/M.N/$SAPI/conf.d/ directory and confirm that the matching PHP version’s packages are installed. A module enabled for one version does not automatically become available to another version installed on the same host.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

If the distribution supplies sockets as part of its PHP build rather than a separately named package, the module may already be compiled and only the SAPI-specific configuration needs to be loaded. The web diagnostic page is the authority for what that request can use.

Enable PHP sockets on Windows

1. Find the php.ini that the web server actually reads

Windows PHP installations can have several executables and configuration files. A web server may not use the php.ini located beside the PHP executable you run in a terminal. Use phpinfo() through the web server and record Loaded Configuration File and Configuration File (php.ini) Path. Edit the loaded file, not merely a similarly named file in another PHP directory.

Also record the PHP version, architecture, and thread-safety mode shown by the diagnostic output. Those details determine whether an extension DLL can be loaded.

2. Confirm that the extension DLL matches the PHP build

Look in the PHP installation’s ext directory, normally under the PHP directory, for the sockets extension DLL supplied for that build. PHP extensions are distributed as php_*.dll files. The DLL must match the PHP major and minor version, CPU architecture, and thread-safety mode of the running PHP binary. It may also require dependent runtime DLLs that must be available to PHP on the system path.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Do not copy an extension DLL from a different PHP release, from a 32-bit installation into a 64-bit installation, or from a non-thread-safe build into a thread-safe build. Such mismatches commonly produce an “Unable to load dynamic library” warning even when the filename appears correct.

3. Activate the extension in the active php.ini

Open the loaded php.ini and find the sockets extension directive. If the distribution includes a commented sockets line, remove its leading semicolon. If no line exists, add the extension directive using the filename or extension name supported by that PHP build. Keep extension_dir pointed at the directory containing the matching extension DLL.

Do not enable the same DLL twice. Duplicate directives can create startup warnings and make troubleshooting harder.

4. Restart the Windows web integration

Save php.ini, then restart the process that hosts PHP: Apache, IIS FastCGI, or the relevant PHP process manager. PHP reads extension settings at process startup, so refreshing a browser tab without restarting the worker does not apply the change.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

5. Verify and inspect logs if it is missing

Open phpinfo() through the web server again and confirm that the sockets section appears. If it does not, inspect the PHP error log and the web-server error log for the startup warning. The message usually identifies the active configuration file, extension path, missing dependency, or build mismatch that prevented loading.

Once the module appears, use the minimal function_exists('socket_create') test, then remove the diagnostic page.

Compile sockets into a source build

When PHP is compiled from source, sockets is enabled at compile time. Configure the build with:

./configure --enable-sockets

The PHP source tree’s sockets build definition declares this option and builds the extension. Add it to the other configure options used for your installation, then compile and install PHP according to your build process. Rebuilding only an application or restarting a service cannot add an extension that was omitted from the PHP binary.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

After installing the rebuilt binary, repeat the SAPI-specific configuration work. Confirm that the web server points to the rebuilt PHP installation rather than an older binary still present on the host. Restart the Apache module, PHP-FPM workers, CGI process, or IIS FastCGI integration that serves requests, and verify with phpinfo().

Keep the source-build configuration and installed paths documented. A later package upgrade or service-file change can switch the server back to a different PHP binary, making sockets appear to have disappeared even though the extension was compiled successfully into the custom build.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Why CLI sockets works while Apache or PHP-FPM fails

This symptom almost always indicates a SAPI or version mismatch rather than a problem with the socket_create() call itself. Compare the CLI output with the web diagnostic page:

Check CLI Web request
Executable or runtime command -v php and php -v PHP version shown by phpinfo()
Configuration php --ini Loaded Configuration File and additional scan directory
SAPI CLI Apache module, PHP-FPM, CGI, or IIS FastCGI
Module state php -m Sockets section in phpinfo()

If the versions differ, enable sockets in the configuration belonging to the web version and restart that version’s service. If the versions match but the loaded configuration paths differ, edit or enable the module in the web SAPI’s configuration tree. If both outputs agree that sockets is loaded, the undefined-function error may be coming from a different host, container, pool, or deployment than the one you tested.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Troubleshoot common failure messages

Call to undefined function socket_create()

  • Check the SAPI handling the failing request with phpinfo().
  • Verify that the sockets section is present for that SAPI.
  • Confirm that the PHP version serving the request is the one where you enabled the extension.
  • Restart the long-running web process after changing configuration.

Do not treat a successful php -m result as proof that the web request has sockets.

phpenmod sockets reports no module

  • Check the installed PHP version and the version used by the web server.
  • Search the distribution repositories for the sockets component matching that PHP stream.
  • Inspect the matching /etc/php/M.N/$SAPI/conf.d/ directory for the module configuration.
  • Verify whether sockets is already compiled into the distribution build and simply absent from the SAPI you tested.

Windows: “Unable to load dynamic library”

Read the full warning in the PHP or web-server error log. Check, in this order:

  1. The php.ini path reported by web phpinfo().
  2. The value of extension_dir.
  3. Whether the sockets DLL exists in that directory.
  4. PHP version, architecture, and thread-safety compatibility.
  5. Required dependent DLLs and their availability to the PHP process.

After correcting a mismatch, restart Apache, IIS FastCGI, or the relevant PHP worker and check the log again. A stale worker can continue reporting the old failure until it is restarted.

The sockets section still does not appear after a restart

First verify that you restarted the process actually serving the request. Then recheck Loaded Configuration File; an administrator may have edited a file that the SAPI does not read. On a multi-version Linux host, inspect the version-specific SAPI directory. On Windows, confirm that the web server is not pointing at a second PHP installation. Finally, review startup logs for a syntax error, duplicate directive, missing DLL, or incompatible build.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use a safe verification procedure in production

Diagnostics should be temporary and restricted:

  1. Perform module checks from the server shell where possible.
  2. If a web check is necessary, create the smallest possible temporary phpinfo() or function_exists() page.
  3. Use an access restriction or a non-public test host while the page exists.
  4. Test the exact URL, virtual host, and application pool that will use sockets.
  5. Delete the diagnostic file immediately after verification.

After activation, test the application’s own error path and permissions separately. Loading the extension only proves that PHP can resolve the socket functions; it does not guarantee that a firewall, operating-system policy, destination service, DNS configuration, or application timeout will permit a particular network connection.

Deployment checklist

  • Identify the PHP version and SAPI serving the application.
  • Check sockets in that SAPI, not only in CLI.
  • On Debian- or Ubuntu-style systems, use the matching version’s phpenmod sockets workflow when the packaged module is disabled.
  • On Windows, use the active php.ini, a compatible extension DLL, and the correct extension_dir.
  • For source builds, include --enable-sockets during PHP configuration.
  • Restart the long-running PHP or web-server process after every configuration change.
  • Confirm the sockets section and function_exists('socket_create') through the web SAPI.
  • Remove every phpinfo() or test page after checking.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.