Hi,
I am using PHP 5.1.2 with curl enabled. But whenever I try to use curl
to fetch a url, it fails - 'curl_exec()' returns nothing.
But if I try to execute the same file in CLI - like 'php curl.php', the
script works properly. However if I try it in a browser, nothing is
returned.
The code is...
curl.php
----
<?php
$ch = curl_init("http ://localhost/");
curl_setopt($ch , CURLOPT_URL, "http://localhost/data.txt");
curl_setopt($ch , CURLOPT_RETURNT RANSFER, true); //Just return the data
- not print the whole thing.
curl_setopt($ch , CURLOPT_HEADER, false); //We need the headers
curl_setopt($ch , CURLOPT_NOBODY, false); //The content - if true, will
not download the contents
print curl_exec($ch);
curl_close($ch) ;
----
--
Binny V A http://www.bin-co.com/php/ 4 12167
On 5 Nov 2006 10:25:29 -0800, "BinnyVA" <bi*****@gmail. comwrote:
>I am using PHP 5.1.2 with curl enabled. But whenever I try to use curl to fetch a url, it fails - 'curl_exec()' returns nothing.
But if I try to execute the same file in CLI - like 'php curl.php', the script works properly. However if I try it in a browser, nothing is returned.
The code is...
curl.php ---- <?php $ch = curl_init("http ://localhost/"); curl_setopt($c h, CURLOPT_URL, "http://localhost/data.txt"); curl_setopt($c h, CURLOPT_RETURNT RANSFER, true); //Just return the data - not print the whole thing. curl_setopt($c h, CURLOPT_HEADER, false); //We need the headers curl_setopt($c h, CURLOPT_NOBODY, false); //The content - if true, will not download the contents print curl_exec($ch); curl_close($ch ); ----
As there's nothing obviously wrong with the code you posted:
- Are you sure you're using the same instance of PHP? (CLI vs Apache module)
- Is cURL statically compiled into PHP or a loadable module?
- Do you have error_reporting set to the maximum and display_errors turned on
to see any errors?
- You could do some more error checking of the return values, and look at
curl_error()
Could be some sort of environment issue, but not much information to go on so
could be something else.
--
Andy Hassall :: an**@andyh.co.u k :: http://www.andyh.co.uk http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Thanks for the help.
- Are you sure you're using the same instance of PHP? (CLI vs Apache
module)
Yes - I did not compile php myself - I just used what came with the
OS(FC5).
- Is cURL statically compiled into PHP or a loadable module?
I think it is statically compiled - as I said, it came with the OS.
Anyway
the 'Configure Command'(in php_info) had this '--with-curl' - that
means it is
statically compiled, right?
- Do you have error_reporting set to the maximum and display_errors
turned on to see any errors?
No.
- You could do some more error checking of the return values, and
look at
curl_error()
Made some changes to the code...
header("content-type:text/plain");
error_reporting (E_ALL);
$ch = curl_init("http ://localhost/");
curl_setopt($ch , CURLOPT_URL, "http://localhost/data.txt");
curl_setopt($ch , CURLOPT_RETURNT RANSFER, true);thing.
curl_setopt($ch , CURLOPT_HEADER, false);
curl_setopt($ch , CURLOPT_NOBODY, false);
$response = curl_exec($ch);
if(is_int($resp onse)) {
die(curl_error( $ch));
}
print "'$response'\n" ;
print_r(curl_ge tinfo($ch));
curl_close($ch) ;
----------------
Now the response is this...
''
Array
(
[url] =http://localhost/data.txt
[http_code] =0
[header_size] =0
[request_size] =0
[filetime] =-1
[ssl_verify_resu lt] =0
[redirect_count] =0
[total_time] =0
[namelookup_time] =0.000296
[connect_time] =0
[pretransfer_tim e] =0
[size_upload] =0
[size_download] =0
[speed_download] =0
[speed_upload] =0
[download_conten t_length] =0
[upload_content_ length] =0
[starttransfer_t ime] =0
[redirect_time] =0
)
--------------
Could be some sort of environment issue, but not much information
to go on so could be something else.
What information do you need?
--
Binny V A
http://binnyva.blogspo t.com/
Hello everyone,
I have solved this problem - the cause was SELinux.
After a while, I gave up on curl and tired to access the url using
fsockopen - the script failed with a 'Permission denied' error. A
search later, I found this was due to SELinux.
So I disabled SELinux...
Open /etc/selinux/config
Add the line 'SELINUX=disabl ed'
Reboot the system
Note : You have to be root to do this.
Now both fsockopen and curl is working fine.
--
Binny V A http://www.bin-co.com/php/ - Many PHP functions
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Haluk Durmus |
last post by:
Hello
I checked out openssl,mm,apr,apr-util,apache 2,curl,libxml and php
from cvs.
php couse an ERROR
I did the following steps:
|
by: Bib |
last post by:
I'm working on a box that allegedly has curl support, but when I run a
script that access curl, I get this error:
Fatal error: Call to undefined function: curl_init() in
/usr/local/apache/htdocs/CHECK.php on line 6.
Line 6 is:
$ch = curl_init();
|
by: Chris Fortune |
last post by:
# uname -a
Linux stargate.mxc-online.net 2.4.20-021stab022.2.777-smp #1 SMP Wed Jul 28
17:12:37
MSD 2004 i686 i686 i386 GNU/Linux
I recompiled PHP with mcrypt, openssl, and curl
phpinfo(): http://www.canadiandropshipping.com/hello.php3
Does anyone know why this ssl curl test fails?
http://www.canadiandropshipping.com...t/diag_curl.php
|
by: Rory |
last post by:
I'm just starting to use cURL and having trouble accessing https pages.
All I want to do at this stage is get an https page and display it,
just to test the https get is working. However, I always get either a
CURLE_OPERATION_TIMEOUTED (28) or CURLE_COULDNT_CONNECT (7) error.
I can see from phpinfo() that cURL and SSL are installed, as follows:
CURL support enabled
CURL Information libcurl/7.12.0 OpenSSL/0.9.6b zlib/1.1.4
but my code...
|
by: jsaint |
last post by:
I'm using php 5.1.2 on apache 2.0.54 and am trying to use curl to
connect to an ssl server. Curl works fine using http, and the
command-line client works with https. But, in php, I just get error 7
when trying to connect through https. So, the problem would seem to be
with php's bundled curl support. I am on WinXP, and everything is
installed through binaries. Here's an example of my code:
$ch = curl_init("https://login.yahoo.com");
...
| |
by: Terry |
last post by:
I'm using curl to invoke a php script on the same site/server. It works
great, but if I call it again while it's still running, nothing happens.
Why? Can that be fixed?
Why use curl? To make it run in the background. My host can't use exec
nor flush the output to the browser. But, I can use curl and timeout.
|
by: rottmanj |
last post by:
I am working on a revamp of a previous application that I have written in coldfusion. The application deals with RETS data. The issue that I am having is with using the curl option HTTP_AUTH and CURLAUTH_DIGEST.
When attempting to authenticate against the server. No matter what I try, my authentication always fails. I have made sure to validate the auth information.
In my testings, I have also verified that curl can authenticate via the...
|
by: Flexor |
last post by:
I have a php script that runs from command line and makes an https
request to paypal, using curl. It works fine if I run it from a web
page. It fails if I run it from CLI. The error I get from the CLI:
* About to connect() to api-3t.sandbox.paypal.com port 443
* Trying 216.113.191.88... * connected
* Connected to api-3t.sandbox.paypal.com (216.113.191.88) port 443
* successfully set certificate verify locations:
* CAfile:...
|
by: DustinP |
last post by:
I have installed PHP5 as ISAPI several times per every single guide I could find in the first 50 pages of results on google..
Server is Windows 2008 runing IIS7, phpinfo works and tells me the configuration..
but there is an issue.. i see the following..
Configuration File (php.ini) Path C:\Windows
Loaded Configuration File C:\php\php.ini
PHP in installed to C:\php and the php.ini ONLY exists in that location and the permissions for...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |