Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
This is the best method I've found for single asynchronous cURL's in PHP (great for calling external API's once your own has finished handling the request).
function acURL($url, $fields = array(), $method = 'POST')
# Set method
$cmd = "curl -X ".$method;
# Build fields
foreach ($fields as $key => $value) {
$cmd .= " -F '".$key."'='".$value."'";
# Finally append resource URL
$cmd .= " '".$url."'";
# Ouput stdout/err to nonexistent directory
$cmd .= " > /dev/null 2>&1 &";
# Execute
exec($cmd, $output, $exit);
// print_r($output); # Uncomment for debugging
# Return
return $exit == 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.