unable to use socket_create

Posted on 2006-05-03
Medium Priority
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

Expert Comment

ID: 16597339
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

ID: 16597458
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

ID: 16597799
use protocol of type tcp
$s = socket_create(AF_INET, SOCK_STREAM, SOL_TCP) or die("couldn't create socket");
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.


Author Comment

ID: 16599014
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

ID: 16608230
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

GranMod earned 0 total points
ID: 16629057
Closed, 500 points refunded.
The Experts Exchange
Community Support Moderator of all Ages

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses
Course of the Month14 days, 13 hours left to enroll

839 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