How can optimize my PHP script? It works fine, but it's so slow. It takes almost 1 minute to complete. Is there anything I can do?
Here is my example script
<?php
if ($_GET["email"]) {
$bar = ['493038', '493014', '493762']; //upto 100 bar ids
foreach ($bar as $barid) {
$email = $_GET['email'];
$batch = $_GET['batch'];
date_default_timezone_set('UTC+8');
$today = date("Y-d-m");
$url = "https://someapilink/api";
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$headers = array(
"Content-Type: application/json;charset=UTF-8",
"Accept: application/json, text/plain, */*"
);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
$data = <<<DATA
{
"email": "$email",
"bar": "$barid",
"batch": "$batch",
"date": "$today"
}
DATA;
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($curl);
$httpcode = curl_getinfo($curl,CURLINFO_HTTP_CODE);
}
echo "<br>server returned an HTTP Status code $httpcode";
}
?>