Problems with PHP proc_open on windows

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=127.0.0.1" "--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 I get the conclusion

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

Why is the port parameter ignored? The command works great on the command line.

+8
windows php mysql
source share
3 answers

An error has occurred

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

mysql occurs, so the mysql process actually started.

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

A quick search gives:

http://msdn.microsoft.com/en-us/library/windows/desktop/ms740668%28v=vs.85%29.aspx

and in particular:

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

I do not think this has anything to do with the fact that the port number is "ignored" and there are even fewer problems with the firewall.

It seems that the environment created using proc_open is good enough to start the mysql process, but still not complete enough, so calls to LoadLibrary from within this process to load the network code exactly fail.

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

+3
source share

The $ env argument for 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 environment inheritance work.

I came across this problem specifically, using the symphony / process component to start the PHP process. Everything worked fine on Linux, but the process failed on Windows servers without network access. Using putenv () and NULL for $ env worked fine in both cases of the OS and solved the problem. The effect of putenv () lasts only for the duration of the request that issues it, so it should be safe if your changes will not cause problems with the rest of your script, or there is material in your current environment that should not be visible in the process that opens.

I searched my way here, looking for answers, and the information definitely helped me in the decision. It may have been too long to help the original poster, but perhaps it can help the next person.

+1
source share

try disabling the firewall or enabling the port

0
source share

All Articles