Jump to content

[SOLVED] CURL vs. WireHttp


happywire
 Share

Recommended Posts

[solution]

========================================================

I am setting up and using a cloud service that encodes images.
https://github.com/rosell-dk/webp-convert-cloud-service

The usage of the service works with this example.
https://github.com/rosell-dk/webp-convert-cloud-service/blob/master/docs/api.md#usage-example-php

I am wondering, should I re-write this bit of the code below and use WireHttp instead of CURL?
What negative implications could it have if I do not make use of WireHttp?

<?php

// from https://github.com/rosell-dk/webp-convert-cloud-service/blob/master/docs/api.md#usage-example-php

$ch = curl_init();
curl_setopt_array($ch, [
    CURLOPT_URL => 'http://example.com/wpc.php',
    CURLOPT_POST => 1,
    CURLOPT_POSTFIELDS => [
        'action' => 'convert',
        'file' => curl_file_create($source),
        'salt' => $salt,
        'api-key-crypted' => $apiKeyCrypted,
        'options' => json_encode(array(
            'quality' => 'auto',
        ))
    ],
    CURLOPT_BINARYTRANSFER => true,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HEADER => false,
    CURLOPT_SSL_VERIFYPEER => false
]);

$response = curl_exec($ch);

// The WPC cloud service either returns an image or an error message
// Verify that we got an image back.
if (curl_getinfo($ch, CURLINFO_CONTENT_TYPE) == 'application/octet-stream') {
    $success = file_put_contents($destination, $response);
}
else {
    // show error response
    echo $response;
}

curl_close($ch);

 

Link to comment
Share on other sites

A) there are no negative implications using CURL instead of WireHttp, if you handle your sent and received files / data correct.

B) WireHttp itself makes use of CURL. Besides "CURL" It also uses "fopen" and "socket". The default usage is set to "auto", but you can explicitly tell it which one you prefer, by passing an options array as fourth param to its send() method. For example, this setting want to use "fopen" with a fallback to "socket":

$response = $http->send($url, $data, 'POST', ['use' => 'fopen', 'fallback' => 'socket']);

 

This one only would use CURL:

$response = $http->send($url, $data, 'POST', ['use' => 'curl']);

 

  • Like 2
  • Thanks 1
Link to comment
Share on other sites

57 minutes ago, Sephiroth said:

However that thread you linked, pointed out something about making a PATCH Request.

@Sephiroth I am not sure what "thread" you are referring to or that it is pointing out something about making a PATCH request.
What do you mean?

@horst So in fact it would be very advisable to rewrite the CURL parts of the example code using WireHttp in case a shared hosting does not have the CURL extension installed, right?

Link to comment
Share on other sites

19 minutes ago, Sephiroth said:

Sorry I was referring to topic you posted, the author there had an issue making PATCH Request using WireHttp, I was only pointing that out should you encounter such. 

Thank you.
However I still don't know what you are referring to unfortunately.
Sorry for that.

Have you got a link to that exact topic/thread/post please?
I looked at the repo https://github.com/rosell-dk/webp-convert-cloud-service as well as its open and closed issues and cannot find anything about a PATCH request.
Please, link me to it.. ?

Link to comment
Share on other sites

56 minutes ago, happywire said:

So in fact it would be very advisable to rewrite the CURL parts of the example code using WireHttp in case a shared hosting does not have the CURL extension installed, right?

Yes, if you need this on multiple differend hosts, - or as learning lesson. ?
Otherwise, when only needed once, you are good to go with your custom code in a template or function.

  • Thanks 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...