• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1163
  • Last Modified:

unable to use socket_create

I've been having a horrible time trying to get my IIS 6 server on Win 2k3 to read an authentication validation snippet from another server.  The PHP code I've been trying to use puts together a GET request through a socket to the authentication server and receives an XML snippet in return, validating the ticket sent with the GET.

Anyway, this code won't work, and after fooling around with everything, I've realized that I can't even open a socket on the server.  When I try something simple like:

$s = socket_create(AF_INET, SOCK_STREAM, 0) or die("couldn't create socket");

It dies on me every time and I get the error:

Warning: socket_create(): Unable to create socket [0]: A protocol was specified in the socket function call that does not support the semantics of the socket type requested. in code.php on line 185
couldn't create socket

I've tried all the other methods PHP has for using sockets, and no matter what, the pointer is always null.
1 Solution
So I assume you are going to port 80 on the validation server?  Can you telnet from to port 80 on that server from your IIS server?  Have you tried the fsockopen() function?
Zeek0Author Commented:
No, I'm going to port 443 on the other server.  It's a CAS server, where the user is redirected from my site, logs in and gets a ticket assigned, which I should then be able to validate.  It's the validation that's screwing up.

It's supposed to work like this: User comes to my site, I check their login status in the session, if they aren't logged in I send them to the authentication server, where they sign in, get a ticket assigned upon success, and are redirected back to me.  I then build a request from the user's ticket, send it to the validation server that supplied the ticket, and get back the XML response indicating that the ticket is good and telling me the ID of the user who logged in.  

Just as a test, I've manually entered a URL
(i.e. https://%HOST%/%PATH%?ticket=%TICKET%?param2=%PARAM")
and gotten a valid response from the server, but that's not being sent through the intermediate server hosting my PHP page.  If nothing else, it tells me that the variables I'm using in my request are all correct.  But the problem I'm having occurs well before I even attempt to talk to the server.

I've tried every function PHP supplies to get this to work, and they all end up dead.  fsockopen(), open(), file_get_contents() . . . none of them work.  

I included the socket_create() example because it's not even getting to a connection problem before it craps out - I can't even *open* a socket, let alone connect to anything or pass data.  I suspect it's a problem with my server more than the code, but I was hoping someone might have run into a similar problem using IIS 6 and Win2k3.
use protocol of type tcp
$s = socket_create(AF_INET, SOCK_STREAM, SOL_TCP) or die("couldn't create socket");
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Zeek0Author Commented:
I tried that:
$s = socket_create(AF_INET, SOCK_STREAM, SOL_TCP) or die("<br>couldn't create socket");


Warning: socket_create(): Unable to create socket [0]: An invalid argument was supplied. in code.php on line 185
couldn't create socket


$s = socket_create(AF_INET, SOCK_STREAM, TCP) or die("<br>couldn't create socket");


Notice: Use of undefined constant TCP - assumed 'TCP' in code.php on line 185 Warning: socket_create() expects parameter 3 to be long, string given in code.php on line 185
couldn't create socket
Zeek0Author Commented:
Turns out the problem is with IIS 6.  I got everything to run correctly when I set the application pooling to "IIS 5 Isolation Mode".  
Closed, 500 points refunded.
The Experts Exchange
Community Support Moderator of all Ages
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now