unable to use socket_create

Posted on 2006-05-03
Last Modified: 2012-06-27
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.
Question by:Zeek0
    LVL 9

    Expert Comment

    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?

    Author Comment

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

    Expert Comment

    use protocol of type tcp
    $s = socket_create(AF_INET, SOCK_STREAM, SOL_TCP) or die("couldn't create socket");

    Author Comment

    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

    Author Comment

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

    Accepted Solution

    Closed, 500 points refunded.
    The Experts Exchange
    Community Support Moderator of all Ages

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Join & Write a Comment

    Suggested Solutions

    This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
    Part of the Global Positioning System A geocode ( is the major subset of a GPS coordinate (, the other parts being the altitude and t…
    The viewer will learn how to dynamically set the form action using jQuery.
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now