-
-
Save neopunisher/453023 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<?php | |
define('EMAIL', '[email protected]'); // edit this | |
define('FLICKR_API_KEY', ''); // edit this | |
define('RAPLEAF_API_KEY', ''); // edit this | |
define('USER_AGENT', 'example user agent (http://www.example.com)'); // edit this | |
define('COOKIE_FILE', '/tmp/cookies.txt'); // edit this if needed | |
$default_curl_params = array( | |
CURLOPT_RETURNTRANSFER => TRUE, | |
CURLOPT_FOLLOWLOCATION => TRUE, | |
CURLOPT_MAXREDIRS => 5, | |
CURLOPT_USERAGENT => USER_AGENT, | |
CURLOPT_COOKIEJAR => COOKIE_FILE, | |
CURLOPT_COOKIEFILE => COOKIE_FILE, | |
CURLOPT_TIMEOUT => 10, | |
CURLOPT_CONNECTTIMEOUT => 5, | |
CURLOPT_VERBOSE => TRUE, | |
); | |
$sites = array( | |
'flickr' => array( | |
CURLOPT_URL => 'http://api.flickr.com/services/rest/', | |
CURLOPT_HTTPGET => TRUE, | |
CURLOPT_POST => FALSE, | |
CURLOPT_POSTFIELDS => array( | |
'api_key' => FLICKR_API_KEY, | |
'method' => 'flickr.people.findByEmail', | |
'format' => 'json', | |
'find_email' => EMAIL, | |
), | |
), | |
'rapleaf' => array( | |
CURLOPT_URL => 'http://api.rapleaf.com/v3/person/email/' . EMAIL, | |
CURLOPT_HTTPGET => TRUE, | |
CURLOPT_POST => FALSE, | |
CURLOPT_POSTFIELDS => array( | |
'api_key' => RAPLEAF_API_KEY, | |
), | |
), | |
); | |
$curl = curl_multi_init(); | |
$connections = array(); | |
foreach ($sites as $name => $params){ | |
foreach ($default_curl_params as $key => $value) | |
$params[$key] = $value; // can't use array_merge as CURL_* keys are numeric | |
// convert POSTFIELDS to a query string if using HTTP GET | |
if ($params[CURLOPT_HTTPGET] && !empty($params[CURLOPT_POSTFIELDS])){ | |
$params[CURLOPT_URL] .= '?' . http_build_query($params[CURLOPT_POSTFIELDS]); | |
unset($params[CURLOPT_POSTFIELDS]); | |
} | |
$connections[$name] = curl_init(); | |
curl_setopt_array($connections[$name], $params); | |
curl_multi_add_handle($curl, $connections[$name]); | |
} | |
do { $mrc = curl_multi_exec($curl, $active); } while ($mrc == CURLM_CALL_MULTI_PERFORM); | |
while ($active && $mrc == CURLM_OK) | |
if (curl_multi_select($curl) != -1) | |
do { $mrc = curl_multi_exec($curl, $active); } while ($mrc == CURLM_CALL_MULTI_PERFORM); | |
$output = array(); | |
foreach ($connections as $key => $connection){ | |
$output[$key] = curl_multi_getcontent($connection); | |
curl_multi_remove_handle($curl, $connection); | |
} | |
curl_multi_close($curl); | |
print_r($output); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment