Last active
December 20, 2015 20:18
-
-
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).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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