Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
cURL not returning a handle
Old 02-18-2010, 04:35 AM cURL not returning a handle
dartiss's Avatar
Experienced Talker

Latest Blog Post:
November
Posts: 32
Name: David Artiss
Location: Nottingham, UK
Trades: 0
I've created some WordPress plugins using cURL for file access. One of the users, however, is having an issue.

Now, my program checks if the cURL extensions are installed first and only proceeds if they are - in the case of this user they are. However, the first curl command which is curl_init() is returning nothing - it should return a handle for the other cURL commands to use.

Unfortunately, I can't find a way to find out what is causing this problem - all the cURL commands for error reporting require the handle.

Does anybody know why this could be happening?

David.
dartiss is offline
Reply With Quote
View Public Profile Visit dartiss's homepage!
 
 
Register now for full access!
Old 02-18-2010, 07:37 AM Re: cURL not returning a handle
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Is it returning nothing, or false ?
http://www.php.net/manual/en/function.curl-init.php
Quote:
Return Values

Returns a cURL handle on success, FALSE on errors.
straight from the php manual:
http://www.php.net/manual/en/function.curl-error.php
PHP Code:
  <?php
// Create a curl handle to a non-existing location
$ch curl_init('http://404.php.net/');
curl_setopt($chCURLOPT_RETURNTRANSFERtrue);

if(
curl_exec($ch) === false)
{
    echo 
'Curl error: ' curl_error($ch);
}
else
{
    echo 
'Operation completed without any errors';
}

// Close handle
curl_close($ch);
?>
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 02-19-2010, 03:43 AM Re: cURL not returning a handle
dartiss's Avatar
Experienced Talker

Latest Blog Post:
November
Posts: 32
Name: David Artiss
Location: Nottingham, UK
Trades: 0
Sorry, it's returning False.

The thing is, the cURL commands to output those errors require a handle - and, naturally, I don't have one because the INIT has failed. Any suggestions on how I find out why this has failed?

David.
dartiss is offline
Reply With Quote
View Public Profile Visit dartiss's homepage!
 
Old 02-19-2010, 06:07 AM Re: cURL not returning a handle
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Look at my post, and try to use the second function, from which came the snippet to identify where your problem is.
The hint is "curl_error()".
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 02-19-2010, 06:10 AM Re: cURL not returning a handle
dartiss's Avatar
Experienced Talker

Latest Blog Post:
November
Posts: 32
Name: David Artiss
Location: Nottingham, UK
Trades: 0
But will that work? curl_error is dependant on a valid handle being used -as none was returned from the INIT, will this actually generate an error? I would have thought that, looking at your code, this would be used to report on any errors from the curl_setopt?
dartiss is offline
Reply With Quote
View Public Profile Visit dartiss's homepage!
 
Old 02-19-2010, 06:45 AM Re: cURL not returning a handle
dartiss's Avatar
Experienced Talker

Latest Blog Post:
November
Posts: 32
Name: David Artiss
Location: Nottingham, UK
Trades: 0
No, my mistake - it's not returning false. When I output the content it's blank.

So if I run this (where $filein contains the file name)...

PHP Code:
if (in_array('curl',get_loaded_extensions())===true) {
    
$cURL curl_init($filein);
    if (
$cURL!==false) {
        echo 
"<p>Result of successful curl_init: ".$cURL."</p>"
    } else {
        echo 
"<p>Curl error:".curl_error($cURL)."</p>";
    }

..I get a success. If my user runs it, it still says the curl_init was successful but no handle is output.

David.
dartiss is offline
Reply With Quote
View Public Profile Visit dartiss's homepage!
 
Old 02-19-2010, 07:25 AM Re: cURL not returning a handle
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Ok, so going further, does the $ch returned after the init is really a curl resource?
You can check that with
PHP Code:
if (in_array('curl',get_loaded_extensions())===true) {
    
$cURL curl_init($filein);
    
var_dump($ch);   //should output something like "resource(4) of type (curl)"
    
if ($cURL!==false) {
        echo 
"<p>Result of successful curl_init: ".$cURL."</p>"
    } else {
        echo 
"<p>Curl error:".curl_error($cURL)."</p>";
    }

Another thing, what is the content of $filein ?
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 02-19-2010, 09:24 AM Re: cURL not returning a handle
dartiss's Avatar
Experienced Talker

Latest Blog Post:
November
Posts: 32
Name: David Artiss
Location: Nottingham, UK
Trades: 0
Do you mean $cURL rather than $ch (in my example)? Assuming so, I guess you're wondering whether it's already in use - maybe this will explain the difference between the code working for me and not my user - maybe his WordPress installation is using $cURL as a resource already??

I'll try it and report back.

David.
dartiss is offline
Reply With Quote
View Public Profile Visit dartiss's homepage!
 
Old 02-19-2010, 10:27 AM Re: cURL not returning a handle
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Quote:
Do you mean $cURL rather than $ch (in my example)
My bad...
Yes, it's what I meant. I was looking at the code of the snippet at that moment.

Quote:
I guess you're wondering whether it's already in use
Not necessarily, but it would be good to check.
But I don't think so, as the last call assigning a value to $cURL will replace the preceding value.

My question was more, in this line
PHP Code:
$cURL curl_init($filein); 
What is the value fo $filein ?
The error might be there...

There might be cases where the content of that value can make curl to bail out.
Like the curl_init comment says:
Quote:
Be careful when using spaces in the URL... make sure to replace them with + signs, otherwise it won't work.
Quote:
For some reason on some webservers it may not be able to understand what cURL is doing. If you're getting unexpected results (like getting no output when the URL is valid) while using curl_init(). Add a trailing slash '/' after the url if you haven't done so already.
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 03-03-2010, 07:08 AM Re: cURL not returning a handle
dartiss's Avatar
Experienced Talker

Latest Blog Post:
November
Posts: 32
Name: David Artiss
Location: Nottingham, UK
Trades: 0
The content of $filein is...

http://bit.ly/api?url=http%3A%2F%2Fw...bove-rizoto%2F

As you can see, no spaces. This content works for me but not my user.

I've checked the return from the curl_init and it is NOT returning false, but instead blanks.

Any further thoughts on what this could be?

David.
dartiss is offline
Reply With Quote
View Public Profile Visit dartiss's homepage!
 
Old 03-03-2010, 08:38 AM Re: cURL not returning a handle
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Do you happen to know which version of PHP is installed on your user server ?
Maybe the problem is there, because if it works on your machine, like it does on my server, the problem is located somewhere between the user server and bit.ly ...
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 03-03-2010, 09:40 AM Re: cURL not returning a handle
dartiss's Avatar
Experienced Talker

Latest Blog Post:
November
Posts: 32
Name: David Artiss
Location: Nottingham, UK
Trades: 0
I asked him this early on - 5.2.10.

His CURL extension is active and when I got him to output the CURL config, it matched my own.

Unless he has some kind of CURL installation problem, but then I'd have expected him to have other issues with his WordPress installation.

I assume there doesn't appear to be anything wrong with my code?

David.
dartiss is offline
Reply With Quote
View Public Profile Visit dartiss's homepage!
 
Old 03-03-2010, 09:46 AM Re: cURL not returning a handle
dartiss's Avatar
Experienced Talker

Latest Blog Post:
November
Posts: 32
Name: David Artiss
Location: Nottingham, UK
Trades: 0
BTW, I'm running one PHP version below that - 5.2.9.

I can see some changes were made in 5.2.10. More interestingly, a lot of CURL bugs were fixed in the version after that, although I can't see any that relate to this specific issue...

http://php.net/ChangeLog-5.php

David.
dartiss is offline
Reply With Quote
View Public Profile Visit dartiss's homepage!
 
Old 03-03-2010, 10:11 AM Re: cURL not returning a handle
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Quote:
I assume there doesn't appear to be anything wrong with my code?
No, not that I can spot.
Which makes me think that the problem is not in the bug corrections of the last php release.
I have tested it on a 5.2.12-pl0 release, with a CLI binary on Linux.

Do you happen to know which os is running on your user server ?
If it's a window version, maybe there is something in that build...
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 03-03-2010, 10:22 AM Re: cURL not returning a handle
dartiss's Avatar
Experienced Talker

Latest Blog Post:
November
Posts: 32
Name: David Artiss
Location: Nottingham, UK
Trades: 0
I'm on a Linux build. Not sure about my user.
dartiss is offline
Reply With Quote
View Public Profile Visit dartiss's homepage!
 
Reply     « Reply to cURL not returning a handle
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.45946 seconds with 12 queries