Jump to content

Curl access to alternate port


freedbill

Recommended Posts

my environment: LINUX 2.6.9 Fedora Core 7

Apache 2.2

PHP 5.2.6

 

I am having difficulty using CURL to access a remote server on a non-standard port.

 

Example:  The url (http://socket.carfax.com:8080) should should return the following:  "901 Transaction Error".  Type it into a browser address window and it returns the desired result.

 

The following php script attempts to do the same via CURL, three different ways.  All return the same result....nothing....

 

<?

$ch = curl_init();

curl_setopt ($ch, CURLOPT_URL, "http://socket.carfax.com");

curl_setopt ($ch, CURLOPT_HEADER, 0);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($ch, CURLOPT_PORT, '8080');

$res = curl_exec($ch);

curl_close ($ch);

 

echo ("<br>results of test #1=$res");

 

 

 

$ch = curl_init();

curl_setopt ($ch, CURLOPT_URL, "http://socket.carfax.com");

curl_setopt ($ch, CURLOPT_HEADER, 0);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($ch, CURLOPT_PORT,8080);

$res = curl_exec($ch);

curl_close ($ch);

 

echo ("<br>results of test #2=$res");

 

 

 

$ch = curl_init();

curl_setopt ($ch, CURLOPT_URL, "http://socket.carfax.com:8080");

curl_setopt ($ch, CURLOPT_HEADER, 0);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$res = curl_exec($ch);

curl_close ($ch);

echo ("<br>results of test #3=$res");

 

?>

 

Does anyone have any suggestions what I am doing wrong.  I'm not very familar with CURL but it appears quiet straightforward.

 

Thanks in advance.

Bill

Link to comment
Share on other sites

My output of your script is

 

<br>results of test #1=901
Transaction Error.<br>results of test #2=901
Transaction Error.<br>results of test #3=901
Transaction Error.

 

Seems right? If you get no output at all, there must be an error. Try to put this at the top of the script, to display errors and notices/warnings:

 

error_reporting(E_ALL);
ini_set('display_errors', 'On');

And it's recommended to use full opening tags (<?php instead of <?).

Link to comment
Share on other sites

Yes.  I use it for some other functionality.  BTW.  The output that you received is correct.  That is very encouriging, so I'm having another issue.

 

I'm running on a leased godaddy virtual dedicated server and have complete control of my environment.  I'm just not very knowledgeable when it comes to configuration of Linux or PHP.

 

 

Link to comment
Share on other sites

Could you do a "phpinfo(INFO_MODULES)" and let me know what version of CURL that is installed on your server.  My version is 7.16.14.  I see that the most recent version is 7.19.5.  Doubt if this is the problem but would be interested in knowing your results.

 

Thanks

Bill

Link to comment
Share on other sites

My local server (PHP 5.2.6, Apache 2.2.9, Windows Vista SP1) has libcurl/7.16.0 OpenSSL/0.9.8i zlib/1.2.3. I also successfully tested the script on my hosted server (PHP 5.2.2, Apache 1.3.37, Linux) with libcurl/7.15.3 OpenSSL/0.9.6b zlib/1.2.3. Can you post a cURL script that works on your system?

Link to comment
Share on other sites

Thanks for the version info.  The following script works fine.

 

<?php

error_reporting(E_ALL);

ini_set('display_errors', 'On');

$ch = curl_init();

curl_setopt ($ch, CURLOPT_URL, "http://www.google.com/");

curl_setopt ($ch, CURLOPT_HEADER, 0);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$res = curl_exec($ch);

curl_close ($ch);

 

echo ($res);

 

?>

 

 

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.