I'm having some trouble with a particular cURL command and I'd like to see the headers and responses. In the command line I use -v and it displays everything, however...
In PHP I'm attempting to use:
curl_setopt($curl, CURLOPT_VERBOSE, 1);
However, nothing is being displayed.
I'm using PHP 5.3.24 on Windows Server 2008 on IIS.
Supposedly the info is sent into the stderr stream which I assume means the regular log used for PHP errors - however nothing is going there either. I'm getting no header results for cURL commands that I know are working and those that I know are not working.
My guess is that you need to also return the buffer. This code works under Linux and might work for you under Win2008:
$browser = curl_init();
curl_setopt($browser, CURLOPT_URL, $url);
curl_setopt($browser, CURLOPT_RETURNTRANSFER, true);
curl_setopt($browser, CURLOPT_VERBOSE, true);
$data = curl_exec($browser);
echo $data;
Related
Testing on a local environment (OSX Mavericks, apache server), a curl function is hanging the server every time is is executed.
The incriminating line of code is
$result = curl_exec($ch);
which is initialised thus:
//initialize and setup the curl handler
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->_api_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, count($params));
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
//execute the request
$result = curl_exec($ch);
when executed (having had all the variables parsed) the page just hangs indefinitely. removing the curl_exec command "fixes" the hang problem.
PHP 5.6.11
curl 7.38.0 (x86_64-apple-darwin12.5.0) libcurl/7.38.0
OpenSSL/0.9.8
Apache/2.2.29 (Unix)
this answer (fixing curl_exec hangs in Windows 8 apache) suggests that multiple sessions are the problem... I have tried terminating the session before curl_exec is called but it makes no difference.
I'm out of ideas to try! I have no debugging information because the server is hanging and not returning anything. If anyone has any ideas what I could try i'd be really grateful! Thanks.
The issue was with using OSX's built in server capabilities. Switching over to MAMP - a dedicated local web-serving application for mac - solved the problem.
So I am encountering a strange situation with a php curl request.
It works perfectly when the script is called from the same local network as the server which is running it but when somebody calls it from outside is not working anymore.
This is my code:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, ROOT_DIR."directory/someScript.php");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 1);
$output = curl_exec($ch);
curl_close($ch);
When I run someScript.php manually even from outside the LAN it works just fine. The issue occurs only when it I try to run it by calling it with curl via another php script.
Anybody have any idea? The curl library is enabled. And both scripts are on the same server.
I am using port forwarding on port 80 to make the server visible in the Internet.
I decided to post the solution in case somebody else has the same problem.
In the end I found the cause for this. The problem was that I was calling the script using the external IP instead of the internal one. Further more because of this XAMPP redirected the call to its default page and because I didn't use the output I did not noticed that.
I'm a bit confused here. I have a file provision_test.php which when executed with php provision_test.php will run fine, execute curl, and get the page. But when executed from the web http://example.com/provision_test.php it fails to properly run. I am running Ubuntu Linux 12.04.1 server, x86_64.
Any ideas would be greatly appreciated... and let me know if you need any extra information, I'd be glad to help you help me.
EDIT 1
FILE: provision_test.php
<?php
$domain = "example.net";
$password = "123";
$serverip = "example.com:10000";
$ch = curl_init();
$userpwd = 'root:password';
curl_setopt($ch, CURLOPT_URL, "http://{$serverip}/virtual-server/remote.cgi?program=create-domain&domain={$domain}&pass={$password}&default-features");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_USERPWD, $userpwd);
curl_exec($ch);
curl_close($ch);
?>
The php5-curl package is installed on the system. However I have not specifically enabled curl in the php.ini file. How would I go about doing this?
I can verify that the php5-curl package was installed properly, however I cannot confirm that apache has enabled it. I know from executing it in the command line that curl works.
Additionally, I do not have selinux or something like that on my server.
I'll be running the script again with PHP errors on to see if I find anything tomorrow.
Today I had the same issue as described.
From CLI the script works fine, from the browser it ends up with error 7
Please enable Verbose mode using:
curl_setopt($ch, CURLOPT_VERBOSE, true);
Run the script from CLI
If you have the same problem as I did, it's because of proxy and maybe authentication as well, so you will have to add the following options to your curl script
$proxy = 'url or ip';
$proxy_port = 8080;
$proxy_username = 'username';
$proxy_password = 'password';
curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_PROXYPORT, $proxy_port);
curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxy_username.':'.$proxy_password);
This saved the last 30minutes of my working day ;-D
Hopefully this will be helpfull for you.
I'm using CURL in my php script and I want to write information from CURLOPT_VERBOSE into file. I tried CURLOPT_STDERR but without luck. It still print everything in cmd window. I'm not sure if parameter in curl_setopt($ch, CURLOPT_STDERR, $errFileHandle); should be file handler or file name (both not work).
Running on a Unix based OS? Use the below on the command line to run your script. Using Windows OS, use the command on Cygwin.
php yourPhp.php > yourFile.txt
Or you can just run it in verbose mode with a file handle
<?PHP
$verbosPath = __DIR__.DIRECTORY_SEPARATOR.'verboseOut.txt';
echo "Saving verbose output to: $verbosPath\n";
$handle=curl_init('http://www.google.com/');
curl_setopt($handle, CURLOPT_VERBOSE, true);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($handle, CURLOPT_STDERR,$f = fopen($verbosPath, "w+"));
curl_exec($handle);
fclose($f);
?>
I'm developing a gateway script that needs to send info to another provider's server, and I need to debug the code.
Is there a way, on my own Linux + Apache + PHP server to capture the CURL / XML data from this script?
I know with PHP, that I could see for example the $_POST, $_GET or $_REQUEST data in a script, but with CURL I don't actually get to the http://intranet/capture.php script in my browser - so this doesn't work.
Is there any other way, with a script on the server to capture everything that's passed to the server, and dump it to a database / flat file?
I even tried monitoring /var/logs/http/access_log on the Linux server, but it didn't reveal much
So, how can I see what the CURL script does, exactly, as the server sees it?
what you can try is this.
echo htmlentities(file_get_contents('http://intranet/capture.php'));
I'm not sure if this is what you mean but it does the same as curl (sort of)
You want to see the output of curl
$ch = curl_init(); // initialize curl handle
curl_setopt($ch, CURLOPT_URL, $url ); // set url to post to
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);// allow redirects
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // return into a variable
curl_setopt($ch, CURLOPT_TIMEOUT, 3); // times out after 4s
curl_setopt($ch, CURLOPT_POST, 1); // set POST method
$result = curl_exec($ch); // run the whole process
curl_close($ch);
echo htmlentities($result);
I hope this is what you mean
In this case, you are the client and the provider's server is the server.
Assuming you are running the curl command from the client, all you can get to is what Robert Cabri said.
If you are attempting to look at whats being received by the server, you need to have appropriate access and also need to know what application stack the server is running to serve your request.