What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
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. Distribution packages normally provide a module-enablement workflow; a PHP build compiled from source must be configured with --enable-sockets.
Need a server to try this on? Antihost offers Linux VPS plans with NVMe storage, full root access and a 14-day free trial.
What PHP sockets are—and what “enable” means
PHP sockets are an extension that exposes low-level networking functions such as socket_create(). They are not an application-level library that you install with a project dependency manager. The extension must be present in the PHP build and loaded by the runtime handling your request.
As an Amazon Associate I earn from qualifying purchases.
Free tools Windows power users keep installed
One-click scans. No signup required.
When PHP says socket_create() is undefined, the usual cause is that the sockets extension is not loaded in that runtime. A successful command-line check does not prove that Apache, PHP-FPM, CGI, or IIS FastCGI has loaded it. Each SAPI can use a different executable, php.ini, and configuration directory.
The reliable sequence is:
- Identify the PHP binary, version, and configuration used by the environment you are testing.
- Check whether sockets is already loaded.
- Enable or install the extension for that exact PHP build.
- Restart the SAPI that serves the application.
- Verify with a web-SAPI diagnostic and a minimal function test.
Identify the PHP installation and SAPI before editing anything
Do not start by editing the first php.ini you find. A server can contain several PHP versions, and the shell may use a different version from the web server.
#1 Best Overall
Check the command-line PHP
Run these commands in the shell account used for administration:
command -v php
php -v
php --ini
command -v php shows which executable the shell resolves. php -v identifies its version and build information. php --ini reports the configuration file and additional scanned configuration directories used by that CLI binary.
Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Scan for outdated or missing drivers - takes under a minute3Clear out junk files and repair common Windows errorsThese values describe the CLI SAPI only. They do not necessarily describe an Apache module, PHP-FPM pool, CGI process, or IIS FastCGI worker.
Find out what serves the application
- An Apache installation may use the PHP module integrated into Apache.
- A reverse-proxy setup commonly forwards requests to PHP-FPM.
- Windows deployments may use Apache, IIS FastCGI, or another web-server integration.
- A scheduled job, queue worker, or game-server utility may invoke CLI PHP even when the website uses a different SAPI.
Enable sockets in every SAPI that actually runs code requiring it. Enabling it only for a maintenance shell will not fix a web request, and enabling it only for the web worker will not fix a CLI worker.
Debian- and Ubuntu-style Linux systems
Debian-family PHP packages organize configuration by PHP version and SAPI. A typical layout separates CLI, Apache, and FPM configuration under paths resembling /etc/php/M.N/, with a conf.d directory for enabled modules. The exact version and SAPI directory on your machine are determined by the installed packages.
1. Check whether the CLI already has sockets
php -m | grep -i sockets
The php -m command lists modules loaded by the selected CLI binary. If the output contains sockets, the CLI extension is active. If it prints nothing, continue with the package and configuration checks below.
2. Confirm the matching PHP package and version
Use your operating system’s package search to confirm that the PHP version used by the target SAPI is installed and that its sockets module is available. Package names differ by distribution, PHP release, and packaging stream, so do not copy a package name intended for another version or distribution.
Rank #2
If the server contains several PHP versions, check the version reported by the relevant SAPI rather than assuming the shell’s default version is the one serving the site.
3. Enable a packaged module
When the distribution package is installed but its module is disabled, Debian-family systems commonly provide the phpenmod helper:
sudo phpenmod sockets
The helper creates or enables the appropriate configuration link for the installed PHP version and SAPI. If your host has multiple versions or multiple SAPIs, make sure the command affects the one your application uses. Inspect the corresponding /etc/php/M.N/$SAPI/conf.d/ directory if the helper reports that it cannot find the module.
4. Restart the request-handling process
Configuration changes are read when a long-running process starts. Restart the Apache service or the PHP-FPM service that handles the application; restarting an unrelated service will not reload the PHP configuration. The unit name varies with the distribution and PHP packaging, so use the service manager’s installed unit list rather than guessing.
A CLI command does not need a “CLI restart.” Each invocation starts a new process and reads its configuration immediately. Apache workers and FPM workers, however, keep running until they are reloaded or restarted.
5. Verify the web SAPI, not just the shell
Create a temporary page in the application’s web root containing:
<?php phpinfo();
Request that page through the same hostname, virtual host, and web server path as the application. In the output, record:
Recommended Free Tools
- Loaded Configuration File: the actual
php.iniread by the web worker. - Additional .ini files parsed: module files loaded after the main configuration.
- Server API: the SAPI handling the request.
- Sockets section: its presence indicates that the extension is loaded for that request.
Remove the diagnostic page immediately after testing. A public phpinfo() page discloses paths, versions, build flags, and environment details that should not remain exposed.
Windows PHP installations
On Windows, sockets is loaded from a PHP extension DLL. The web server may not use the php.ini located beside the PHP executable, so the first task is to identify the configuration file actually read by the web process.
1. Find the active configuration file
Use a temporary phpinfo() page through the web server and read Loaded Configuration File. The PHP executable’s directory and the web server’s configuration can point to different files. If you also run php --ini in a console, treat that result as CLI-only until the web page confirms it.
2. Check the extension directory and build compatibility
PHP’s Windows guide places extension DLLs in the PHP ext directory, normally beneath the PHP installation directory. Confirm that the sockets DLL present there was built for the same:
Quick wins for a faster PC:
Clear out junk files and repair common Windows errorsFree Scan →Scan for outdated or missing drivers - takes under a minuteDriver Scan →- PHP major and minor version;
- CPU architecture, such as 64-bit or 32-bit;
- thread-safety mode required by the web integration; and
- PHP API/build family.
Do not copy a DLL from a different PHP release or architecture. A matching filename is not enough: dependent runtime DLLs and the build’s thread-safety and API settings must also be compatible.
3. Edit the active php.ini
Keep extension_dir pointed at the intended ext directory. If the file already contains a sockets extension line, remove the comment marker according to the syntax used by the surrounding extension directives. If no line exists, add the extension directive using the exact filename or extension name supported by that PHP build and the DLL present in ext. Avoid guessing a name when the installed build or its example configuration provides the supported spelling.
4. Restart the web integration
Save the file, then restart Apache, IIS FastCGI, or the PHP process used by the site. A browser refresh alone does not guarantee that an existing worker has discarded the old configuration.
Rank #4
5. Confirm activation and inspect logs
Reload the temporary phpinfo() page and look for the sockets section. If it is absent, inspect the PHP and web-server error logs. Windows commonly reports an “Unable to load dynamic library” warning when the active configuration points to the wrong directory, the DLL has missing dependencies, or its architecture, thread-safety mode, PHP version, or API does not match the running executable.
The Tool Desk
Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →PHP compiled from source
If PHP was built from source, the sockets extension is selected at compile time. Configure the build with:
--enable-sockets
The PHP source tree’s sockets configuration declares that option and uses it to build the extension. Adding an ini line to a binary compiled without sockets cannot create the missing functions.
Build and deploy the matching binary
- Add
--enable-socketsto the configuration options used for the PHP build. - Compile and install that build using the same deployment process used for the rest of the server’s PHP installation.
- Confirm which executable and configuration each SAPI now uses; an old binary may remain in the shell path or in a service definition.
- Apply any SAPI-specific module configuration required by the installation.
- Restart Apache, PHP-FPM, CGI, or the relevant Windows service before testing.
A source build can coexist with distribution PHP packages. That is why checking the executable path, version, loaded configuration file, and Server API is essential after installation.
Verify with a minimal function test
After the module appears in the web-SAPI diagnostic, test the function your application needs:
<?php
var_dump(function_exists('socket_create'));
The expected result is bool(true). This test confirms that the function is available in that request, rather than merely proving that a configuration file contains an extension directive.
Run the same check from the CLI if a command-line worker also needs sockets:
Best Value
php -r "var_dump(function_exists('socket_create'));"
If the CLI and web results differ, compare their PHP versions, php --ini output, loaded configuration paths, and SAPIs. Fix the environment that reports false; do not assume one SAPI’s success applies to the other.
Why sockets works in CLI but not through Apache or PHP-FPM
Different configuration files
The shell’s php --ini output may point to a CLI directory while the web worker reads an Apache or FPM directory. Debian’s version/SAPI layout makes this separation explicit. Use phpinfo() through the web server to identify the web file, then enable the module in that configuration scope.
Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchWindows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallDifferent PHP versions
A server can have more than one PHP stream installed. The command found by command -v php may be newer or older than the binary configured in an Apache module or FPM pool. Compare the version shown by CLI diagnostics with the version shown by web phpinfo().
The worker was not restarted
FPM and Apache processes retain the old module list until they reload. Restart the service that owns the request-handling workers after every configuration change, then repeat the web test.
The request reaches a different host or pool
Virtual hosts, reverse proxies, and multiple FPM pools can send apparently identical URLs to different PHP processes. Test through the same hostname and route used by the failing application, and read the Server API and loaded configuration from that response.
Troubleshooting by symptom
| Symptom | Likely cause | What to check |
|---|---|---|
Call to undefined function socket_create() |
Sockets is not loaded in the SAPI making the call. | Check function_exists('socket_create'), then inspect that SAPI’s module list and loaded configuration file. |
php -m shows sockets, but the website fails |
CLI and web PHP use different versions, SAPIs, or php.ini files. |
Compare CLI output with a web phpinfo() page and enable sockets in the web configuration. |
| Debian helper cannot find sockets | The matching PHP version/module package is absent, or the helper is operating on a different installed stream. | Use package search for the active PHP version and inspect the corresponding /etc/php/M.N/$SAPI/conf.d/ directory. |
| Windows “Unable to load dynamic library” | Wrong extension_dir, missing dependent DLL, incompatible architecture, thread-safety mode, PHP API, or PHP version. |
Read the active php.ini, verify the DLL in ext, check build compatibility, and inspect PHP error logs. |
Module appears in configuration but not in phpinfo() |
The edited file is not the file read by the web worker, or the worker was not restarted. | Use the page’s “Loaded Configuration File” value, then restart the correct Apache, FPM, or FastCGI process. |
| CLI test changes after switching shells | The shell path resolves a different PHP executable. | Run command -v php and php -v again in the affected account and compare paths. |
Restart and verification rules for common deployments
- CLI scripts: no persistent service restart is needed; start a new process after changing configuration.
- Apache PHP integration: restart or reload the Apache service that loads PHP, then request the diagnostic page through that virtual host.
- PHP-FPM: restart or reload the FPM pool/version serving the site, not an unused pool for another PHP release.
- CGI or IIS FastCGI: recycle the worker process or restart the configured web service so it reads the changed DLL and
php.ini. - Long-running application workers: restart those workers separately; they may not share the web server’s process lifecycle.
After restarting, perform both checks: the module list or sockets section must appear, and function_exists('socket_create') must return true in the failing execution context.
Choosing the right enablement approach
| Deployment model | Primary action | Important qualification |
|---|---|---|
| Debian/Ubuntu-style package | Check php -m; if the packaged module is disabled, use phpenmod sockets. |
Version and SAPI-specific directories can differ; package names are not universal. |
| Windows PHP | Use the web-loaded php.ini, compatible sockets DLL, correct extension_dir, and restart the web integration. |
Architecture, thread-safety, PHP API, dependencies, and active configuration must all match. |
| Self-compiled PHP | Build with --enable-sockets, deploy the resulting binary, configure each SAPI, and restart services. |
An ini directive cannot add sockets to a binary that was compiled without the extension. |
Production checklist
- Record the PHP version and executable for every execution context that needs sockets.
- Identify the Server API handling the failing request.
- Check the active configuration path rather than editing a presumed
php.ini. - Confirm that sockets is listed for that SAPI.
- On packaged Linux, verify the matching module package and use the distribution’s module helper when appropriate.
- On Windows, verify the extension DLL,
extension_dir, architecture, thread-safety mode, PHP API, and dependent DLLs. - For source builds, ensure the binary was configured with
--enable-sockets. - Restart the long-running web or worker process after changing configuration.
- Test
function_exists('socket_create')through the same route that previously failed. - Delete temporary
phpinfo()and function-test pages when verification is complete.
Once the extension is loaded in the correct SAPI and the process has been restarted, PHP’s socket functions become available to the application. If the result is still negative, the remaining fault is almost always an environment mismatch: wrong binary, wrong configuration file, wrong service, or an incompatible Windows DLL.
Quick Recap
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.




