This is the script I need to speed up.
Things that I have already done to speed up are:
- Using single quotes instead of double quotes wherever possible.
- Created Database Index
- Replaced queries containing 'select' * with 'select column_names'
It takes around 1.7 seconds per URL on average. I want to know if this can be made any faster by any optimizations in PHP or SQL.
<?php
$servername = '127.0.0.1';
$username = 'root';
$password = '';
$dbname = 'cron';
$conn = mysqli_connect($servername, $username, $password, $dbname);
if (!$conn)
{
die('Connection failed: ' . mysqli_connect_error());
}
$sql = 'SELECT Name FROM domain';
$result = mysqli_query($conn, $sql);
while ($row = mysqli_fetch_row($result))
{
$line = (string)$row[0];
$auth = base64_encode('ABC:XYZ');
$aContext = array('http' => array('proxy' => 'tcp://IP_ADDRESS', 'request_fulluri' => true, 'header' => 'Proxy-Authorization: Basic'.' '. $auth,),);
$cxContext = stream_context_create($aContext);
if (strstr(file_get_contents('http://www.google.com/search?q=site:'.$row[0], False, $cxContext), 'did not match any documents'))
{
$status = FALSE;
}
else
{
$status = TRUE;
}
date_default_timezone_set('Asia/Kolkata');
$date = date('Y-m-d H:i:s');
$sql = "UPDATE domain SET Index_Status = '$status', Last_Checked = '$date' WHERE Name = '$line' ";
$result1 = mysqli_query($conn, $sql);
}
mysqli_close($conn);
header( 'Location: /Cron/php/display.php');
?>