Giter Site home page Giter Site logo

kraken-php's Issues

cURL error due to AddTrust root certificate expiration

On May 30th, 2020, the AddTrust root certificate expired and has caused connectivity issues in many services. https://packetstormsecurity.com/files/157891/Ubuntu-Security-Notice-USN-4377-1.html

This repository uses its own certificate bundle https://github.com/kraken-io/kraken-php/blob/master/lib/cacert.pem which is now outdated and causes cURL requests to fail https://github.com/kraken-io/kraken-php/blob/master/lib/Kraken.php#L87 even though the system's certificate bundle is up-to-date.

Add stable tags versions

The next step after composer.json is adding stable version releases through git tag e.g.
release-1.0
release-1.1
...
release-2.x
etc.

Returning HTTP status

I'm wondering if the HTTP status codes could be returned from the Kraken->request() method to improve error handling?

https://kraken.io/docs/http-status-codes

Possibly something like this:

private function request($data, $url, $type) {
    $curl = curl_init();

    if ($type === 'url') {
        curl_setopt($curl, CURLOPT_HTTPHEADER, array(
            'Content-Type: application/json'
        ));
    }

    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_POST, 1);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
    curl_setopt($curl, CURLOPT_FAILONERROR, 0);
    curl_setopt($curl, CURLOPT_HEADER, 1);

    $response = curl_exec($curl);

    $header_size = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
    $response = json_decode(substr($response, $header_size), true);

    if (!isset($response["http_status"])) {
        $response["http_status"] = curl_getinfo($curl, CURLINFO_HTTP_CODE);
    }

    curl_close($curl);

    return $response;
}

Add support for curl timeout

Something like the following:

class Kraken 
{
    protected $timeout              = 0;
    protected $connection_timeout   = 0;

    <snipped>

    public function setTimeout($seconds)
    {
        $this->timeout = $seconds;
    }

    public function setConnectionTimeout($seconds)
    {
        $this->connection_timeout = $seconds;
    }

    private function request($data, $url, $type) 
    {
        $curl = curl_init();
        if ($type === 'url') {
            curl_setopt($curl, CURLOPT_HTTPHEADER, array(
                'Content-Type: application/json'
            ));
        }
        curl_setopt($curl, CURLOPT_URL, $url);

        // Force continue-100 from server
        curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.85 Safari/537.36");
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
        curl_setopt($curl, CURLOPT_FAILONERROR, 0);

        //set connection timeout if value is greater than zero
        if($this->connection_timeout > 0) {
            curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, $this->connection_timeout);
        }

        //set timeout if value is greater than zero
        if($this->timeout > 0) {
            curl_setopt($curl, CURLOPT_TIMEOUT, $this->timeout);
        }

        $response = json_decode(curl_exec($curl), true);
        if ($response === null) {
            $response = array (
                "success" => false,
                "error" => 'cURL Error: ' . curl_error($curl)
            );
        }

        curl_close($curl);
        return $response;
    }

}

You can see my additions as I snipped some of the code out for reading purposes eg.:

protected $timeout              = 0;
protected $connection_timeout   = 0;

and

public function setTimeout($seconds)
{
    $this->timeout = $seconds;
}

public function setConnectionTimeout($seconds)
{
    $this->connection_timeout = $seconds;
}

As well as:

//set connection timeout if value is greater than zero
if($this->connection_timeout > 0) {
    curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, $this->connection_timeout);
}

//set timeout if value is greater than zero
if($this->timeout > 0) {
    curl_setopt($curl, CURLOPT_TIMEOUT, $this->timeout);
}

I'm going to write a PR as soon as possible.

Error while pushing file to S3

$original_upload_params = Array(
[file] => /tmp/phpH6Vxhr
[wait] => 1
[lossy] => 1
[s3_store] => Array(
[key] => XXXXXXXXXXXXX
[secret] => CCCCCCCCCCC+XXXXXXXXXX
[bucket] => b.fitn.in
[region] => ap-southeast-1
[headers] => Array(
[Cache-Control] => max-age=2592000000
[Expires] => Wed, 11 Apr 2096 20:25:37 GMT
)
[path] => f/l/1767_1422890642.png
)

                            [resize] => Array
                                (
                                    [width] => 100
                                    [strategy] => landscape
                                )

)

$original_response = Kraken::upload($original_upload_params);

Its giving me an error
Array
(
[message] => Error while pushing file to S3: Expected params.Expires to be a Date object, ISO-8601 string, or a UNIX timestamp
[success] =>
)

Add Composer functionality

It's hard to use any php library these days without it being compatible with composer. Can you please list it on packagist.org and add a composer.json file?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.