kraken-io / kraken-php Goto Github PK
View Code? Open in Web Editor NEWOfficial Kraken.io library for PHP - https://kraken.io
Official Kraken.io library for PHP - https://kraken.io
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.
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;
}
Hey guys,
could you quickly publish 1.6 via packagist? :) Latest version there still is 1.5
Cheers
Fabian
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.
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.
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?
$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] =>
)
Since 2 days ago and the kraken DB outage, I'm getting this error "Error while creating temporary directory in file storage."
Any solutions please ?
Thanks you
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.