Check if a site is indexed by google and stores status in Database 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.

&lt;?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' =&gt; array('proxy' =&gt; 'tcp://IP_ADDRESS', 'request_fulluri' =&gt; true, 'header' =&gt; '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');
?&gt;
First of all, changing between double and single quotes is going to make such a trivial difference, you would probably need to measure to microsecond precision to see any performance impact. Use quote styles that make your code most readable in whatever context you are forming strings.

The main thing you can do to speed things up is to parallelize the requests against Google and then batch your update queries for each batch of requests.

Using curl_multi may be a good approach. I actually have a simple REST library that leverages curl_multi that you are free to use if you find it helpful - https://github.com/mikecbrant/php-rest-client

Obviously, making requests in parallel will consume more memory and CPU on your server, so you might need to play around with number of concurrent requests to get your desired compromise of run time vs. resource utilization. 

You also need to make sure you have an index on your Name field in the DB.

Don't use root user in MySQL, and especially don't leave root user with empty password.