Skip to content

Instantly share code, notes, and snippets.

@brod-ie
Last active December 20, 2015 20:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brod-ie/6188897 to your computer and use it in GitHub Desktop.
Save brod-ie/6188897 to your computer and use it in GitHub Desktop.
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