Welcome Guest, Not a member yet? Register   Sign In
CURLRequest.php
#1

HI there CI guys. You're all doing a great job and am looking forward to the production product. 

I've been working on some practice projects  and I ran into an issue using cURL. 

My objective is to get the contents of a webpage and extract the title. Whenever I tried to use the cURL library to access an external page I would get the follow error message in my log. 

curl_setopt_array(): cannot represent a stream of type Output as a STDIO FILE*

So I started digging around and I think I discovered what was causing my issue. The issue in the CURLRequest.php file in the function setCURLOptions(). Please see the following section of code currently starting around line 676 of the file. 

  if (isset($config['debug']))
  {
   $curl_options[CURLOPT_VERBOSE] = $config['debug'] === true ? 1 : 0;
   $curl_options[CURLOPT_STDERR]  = is_bool($config['debug']) ? fopen('php://output', 'w+') : $config['debug'];
  }

The problem I'm having is that this runs even when I don't set the debug param in the curl request. See
$response = $client->request('GET', "http://something/something", [
     'auth' => ['user', 'pass']    
     
   ]);

For now I have worked around this by commenting out line 78  where the 'debug' param is set by the class file. See

protected $config = [
  'timeout'         => 0.0,
  'connect_timeout' => 150,
  //'debug'           => false,
  'verify'          => true,
 ];

Another workaround was to change "php://output" to a file location so it doesn't open a stream. 

Anyways, either I am using your cURL library incorrectly or maybe there should be a different way to setting the debug format . 

Any feedback you guys can provide would be helpful. 

Oh and if you have any suggestions on how to use the CI cURL library (based on guzzle) to extract the title out of a webpage. I still haven't figured that out yet.

Cheers all. and thanks for all your hard work.
Reply
#2

It looks like we should be checking not just if debug is a bool but if it's true.... Looks like a bug. I'll post an issue over at GitHub about this. Thanks for reporting!
Reply
#3

Additionally, I'd like to ask about the getBody() function. $response->getBody() doesn't seem to return any content. I'm trying to return HTML file using the client request method. I can see the headers. I cannot see a body.
Does anyone have an example of returning html content to a response? I'm not sure if this is a bug or not. Can anyone confirm?

Thanks.
Reply
#4

I just pushed a potential fix for the CurlRequest debug issue. Can you confirm it for me?

As for your other issue - I'm a little confused what you're trying to do? Can you be more specific.
Reply
#5

Hi Kil. Sorry to report but I dont think I can test this properly afterall. I've had to change computers and my environment is limited to PHP 7.1 for now.

Thanks for looking at this. Maybe someone else can test?
Reply
#6

Kil , where should I pull the updated files from?
Reply
#7

The develop branch.
Reply
#8

Still not working. Getting a SetOptArray error message.

This is the code Im trying to use.

$client = \Config\Services::curlrequest();

$response = $client->request('GET', $url, ['body' => 'html']);

echo $response->getHeader('Content-Type');

The short error message I get is

curl_setopt_array(): supplied argument is not a valid File-Handle resource

Again not sure what I'm doing wrong.
Reply
#9

(This post was last modified: 05-28-2019, 08:20 AM by mightyted.)

Just reading this thread.

https://forum.codeigniter.com/thread-73722.html

I didn't know that libcurl was a different entity. I guess this is the cause of my problem.


Thanks.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB