I pull results from my database, with a while I process each result. Now I would like to run all these results simultaneously. Is this possible with php?
Below I added a example code, I would like to have that for each result the query is executed simultaneously without waiting for the other results to be completed before going to next.
while ($accountdata = mysql_fetch_array($qaccountdata))
{
$un = $accountdata['email'];
mysql_query("INSERT INTO log (id, email, item,height, stamp) VALUES ('', '$un','something','', '" . strtotime('now') . "')");
}
What about something like this? script.php contains the process.
<?php
$q = 1;
$mh = curl_multi_init();
while ($accountdata = mysql_fetch_array($qaccountdata)) {
$a = $accountdata['email'];
$ch.$q = curl_init();
curl_setopt($ch.$q, CURLOPT_URL, 'script.php?id='.$a);
curl_setopt($ch.$q, CURLOPT_HEADER, 0);
curl_multi_add_handle($mh,$ch.$q);
$q++;
}
$active = null;
//execute the handles
do {
$mrc = curl_multi_exec($mh, $active);
} while ($mrc == CURLM_CALL_MULTI_PERFORM);
while ($active && $mrc == CURLM_OK) {
if (curl_multi_select($mh) != -1) {
do {
$mrc = curl_multi_exec($mh, $active);
} while ($mrc == CURLM_CALL_MULTI_PERFORM);
}
}
curl_multi_remove_handle($mh, $ch.$q);
curl_multi_close($mh);
?>
Script.php
if (isset($_GET['type'])) {
$_GET['id'] = $un
//rest of code
}