8

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 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.

asked Mar 28, 2012 at 22:45
4
  • 2
    does it work from the cmd line? It could a permission problem. (that being said, why not using the mysql extension? :) Commented Apr 1, 2012 at 13:38
  • Hmmm... a MySQL connection library in PHP? Interesting... Commented Apr 2, 2012 at 19:32
  • have you tryed to include the windows folder in a path env var? Commented Apr 3, 2012 at 17:21
  • mysql is fired up, just would like to blast into the server a file of SQL. Commented Apr 9, 2012 at 18:25

3 Answers 3

3
+50

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:

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'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.

answered Apr 3, 2012 at 2:20
Sign up to request clarification or add additional context in comments.

Comments

3

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.

answered May 22, 2014 at 19:37

Comments

0

try to turn off your firewall or enable port

answered Apr 2, 2012 at 18:43

2 Comments

if you telnet that port, what content it is on? or, you can't reach the port?
that means, you never open that port. check your code and manual, again.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.