Basically I have written this code that works like a charm, but there is a down side to it (It's really slow).
<?php
error_reporting(E_ALL);
ini_set('display_errors',1);
$account = "localhost:3306";
$username = "root";
$password = "luca170385";
$db = "accounts";
$con = new mysqli($account , $username, $password, $db);
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
} else {
echo "Selected database. <br>";
}
$sql = "SELECT `address` FROM `url` WHERE `code` IS NULL";
if ($result = mysqli_query($con,$sql)) {
while ($row = mysqli_fetch_array($result)){
$url = ($row["address"]);
$handle = curl_init($url);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($handle, CURLOPT_CONNECTTIMEOUT ,2);
$response = curl_exec($handle);
$httpCode = curl_getinfo($handle, CURLINFO_HTTP_CODE);
echo "HTTP-CODE = $httpCode <br>";
$sql2 = "UPDATE `url` SET `code` = $httpCode WHERE `address` = '".$url."'";
$con->query($sql2) or die(mysqli_error($con));
$con->commit();
if ($con->error) {
printf("Errormessage: %s
", $con->error);
}
}
printf ($row["address"]);
}
mysqli_close($con);
curl_close($handle);
?>
What the code does, is it looks into my database, gets a URL where HTTP-CODE is NULL and checks the HTTP-CODE and places the answer in the database, but like I said that bit works, is there a way to maybe run the script multiple times but all at the same script?, I am welcome to all input. Thanks!