Jump to content

fsockopen to curl problem..


btray77

Recommended Posts

I have the original code of:

 

if (@fsockopen($_SERVER['SERVER_NAME'], $c[1], $errno, $errstr, $portcheck))

 

I'm wanting to convert that to use CURL.

 

I've tried the following with no luck.  What am I doing wrong?

 

$cx = curl_init($_SERVER['SERVER_NAME']);

curl_setopt($cx, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($cx,curlOPT_port,$c[1]);

curl_setopt($cx, CURLOPT_FAILONERROR,true);

curl_setopt($cx, CURLOPT_TIMEOUT, $portcheck);

$temp = curl_exec($cx);

if (!curl_errno($cx))

 

There are some ports that should give an error and some that should not.  The code it to tell me if the port is giving error or not.  (aka is DNS/POP3/SMTP/ETC server up/down)

 

 

 

Also second part question.  What would I have to do to test to see if I could use fsockopen or if I need to use curl.

 

 

Thank you

-Brad

Nissan 350z

Link to comment
Share on other sites

i don't think this would work because curl will send an http request to a working POP server then say there is an error because POP did not respond like a HTTP server so there for the script would say the service is down you could try using stream_socket_server()

$sock = stream_socket_server("tcp://{$_SERVER['SERVER_NAME']}:{$c[1]}");
stream_set_timeout($sock,$portcheck);
if($sock){
//port ok
}else{
//port error
}

not exactly sure but that should work although it might wait 30 seconds because of when the timeout is set

 

Scott.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.