Home » Php » mysql – PHP proc_open problems on windows

mysql – PHP proc_open problems on windows

Posted by: admin July 12, 2020 Leave a comment


I have the following code

$env=array('PATH'=>'C:\Program Files\MySQL\MySQL Server 5.1\bin',
           'PATHEXT' => '.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC');
$cmd='mysql "--port=3306" "--host=" "--user=root" "--password=xxxx" <"C:\Projects/script.sql" 2>&1';
print $cmd;
$proc = proc_open($cmd, $descriptorspec, $pipes, NULL, $env) or die("Cannot run $cmd");

while ($line=fgets($pipes[1])) print $line;

print "\n\nCompleted\n";

And the output I get is

ERROR 2004 (HY000): Can't create TCP/IP socket (10106)

Why is the port option being ignored? The command works perfectly well on the command line.

How to&Answers:

The error seen

ERROR 2004 (HY000): Can't create TCP/IP socket (10106)

is raised by mysql, so the mysql process actually started.

This error corresponds to CR_IPSOCK_ERROR, and it prints the underlying root cause of the problem: 10106.

A quick search gives:


and in particular:


Service provider failed to initialize.
The requested service provider could not be loaded or initialized. This error is returned if either a service provider's DLL could not be loaded (LoadLibrary failed) or the provider's WSPStartup or NSPStartup function failed.

I don’t think this has anything to do with the port number being “ignored”, and even less firewall issues.

It appears as if the environment created by proc_open is good enough to start the mysql process, but yet not complete enough so that calls to LoadLibrary from within that process, to load the networking code namely, are failing.

The same command works from the command line, most likely because the environment in the command line contains much more.


The $env argument to proc_open replaces the current environment, but if it is NULL, the environment of the current process is used.

A possible solution would be to use putenv() to change the current environment instead of specifying a new array for $env. Let the environment inheritance work.

I encountered this issue specifically using the symphony/process component to launch a PHP process. Everything worked fine in linux, but the process failed in windows servers with no network access. Using putenv() and NULL for $env worked fine under both OS cases, and solved the problem. The effect of the putenv() only lasts for the duration of the request that issues it, so it should be safe unless your changes cause issues with the rest of your script, or there there is stuff in your current environment that should not be seen in the opened process.

I googled my way here looking for answers, and the information definitely helped me to a solution. It has probably been too long to help the original poster, but maybe it can help the next person.


try to turn off your firewall or enable port