function makeGetRequest($url, $headers) {
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1, // return the transfer as a string
CURLOPT_FAILONERROR => 0, // response code greater than 400 cause error
CURLOPT_HEADER => 1, // show curl response headers
CURLOPT_HTTPHEADER => $headers,
CURLOPT_URL => $url,
CURLOPT_CONNECTTIMEOUT => 10, // should only spend 10 seconds attempting to connect
CURLOPT_TIMEOUT => 30, // hould only spend a maximum of 30 seconds executing the request
));
$resp = curl_exec($curl);
curl_close($curl);
return $resp;
}
function makePostRequest($url, $headers, $body) {
$curl = curl_init();
curl_setopt_array( $curl, array(
CURLOPT_RETURNTRANSFER => 1, // return the transfer as a string
CURLOPT_FAILONERROR => 0, // response code greater than 400 cause error
CURLOPT_HEADER => 1, // show curl response headers.
CURLOPT_HTTPHEADER => $headers,
CURLOPT_URL => $url,
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => $body,
CURLOPT_CONNECTTIMEOUT => 10, // should only spend 10 seconds attempting to connect
CURLOPT_TIMEOUT => 30, // hould only spend a maximum of 30 seconds executing the request
));
$resp = curl_exec($curl);
curl_close($curl);
return $resp;
}
-- list all global variables
SHOW GLOBAL VARIABLES WHERE Variable_name = 'sql_mode'
..get sql_mode value - remove ONLY_FULL_GROUP_BY
-- save `sql_mode` new value
SET GLOBAL sql_mode = 'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'
must reconnect to work!
Extended implementation that allows functions to pass a varying number of arguments along.
function waterfall(tasks, cb) {
cb = cb || function() {};
// support for arbitrary # of arguments passed along by functions
var data = Array.prototype.slice.call(arguments, 2);
if (!Array.isArray(tasks)) {
return cb('tasks must be an array');
}
// check if there are functions left
if (!tasks[0]) {
// avoid race condition with
if (data.length > 1) {
cb(null, data);
} else {
cb(null, data[0]);
}
return;
}
// process the next function
var next = tasks[0];
data.push(function(err) {
if (err) {
return cb(err);
}
// build the args for waterfall...
var args = [];
// remaining functions
args.push(tasks.slice(1));
// final waterfall callback
args.push(cb);
// arbitrary # of args for next function
args.push.apply(args, Array.prototype.slice.call(arguments, 1));
process.nextTick(function() {
waterfall.apply(null, args);
});
});
next.apply(null, data);
};
// test
waterfall([
function(next) {
console.log('1st');
setTimeout(next, 1000);
},
function(next) {
console.log('2nd');
setTimeout(next, 1000);
},
function(next) {
console.log('3rd');
setTimeout(next, 1000);
},
function(next) {
console.log('4th');
next(null, 'Hello!');
},
], function(err, res) {
console.log(err, res);
});
function waterfall(arr, cb) {
var fns = arr.slice(1);
if (!arr[0]) {
process.nextTick(function() {
cb(null);
});
return;
}
var first = arr[0];
first(function(err, data) {
if(err) {
return cb(err);
}
waterfall(fns, cb, data);
});
}
waterfall([
function(next) {
console.log('1st');
setTimeout(next, 1000);
},
function(next) {
console.log('2nd');
setTimeout(next, 1000);
},
function(next) {
console.log('3rd');
setTimeout(next, 1000);
},
function(next) {
console.log('4th');
setTimeout(next, 1000);
},
], function(err) {
console.log(err);
});
no nodejs environment helper
var process = {nextTick:function(fn){ setTimeout(fn); }};
UPDATE: 2021-10-27