I have written an C-language extension DLL for PHP, and I am having some trouble opening a socket() inside this DLL.

If I call:

SOCKET socket = socket(AF_INET, SOCK_STREAM, 0 /* IPPROTO_TCP */);

I get an invalid socket back. WSAGetLastError() is 10106, or "The requested service provider could not be loaded or initialized".

Before this call, I call WSAStartup() asking for version 2.0, and that returns OK.

Even if I don't call WSAStartup() (thinking the socket stuff may have been initialized by the PHP runtime), I still get the 10106 error back from the socket() call.

Anyone have any tips on how to make socket calls from within a PHP extension DLL, or clue as to what I'm doing wrong?

    Apparently, I need to have "SYSTEMROOT" set in my environment, or the WinSock calls don't work...

    Normally this variable is inherited from the Windows environment, but as PHP.exe is being called as a CGI with CreateProcess() with its own env, this variable was missing.

      Write a Reply...