curl ping数据库中的URL并在网页上发布时间

So I'm currently trying to ping urls in a db table that should then post the 'LIVE' or 'DOWN' status of that url on a web page if the ping was successful, Before I tried it this way I had it set up as a php array with fsocket which worked.

Currently when I use the code as shown below it does pull the data from the db table but the badge showing 'LIVE' or 'DOWN' constantly shows 'DOWN'.

<?php
require_once "config/config.php";

$sql = "SELECT * FROM deployments";
 if($result = mysqli_query($link, $sql)){
 if(mysqli_num_rows($result) > 0){
  echo "<tr>";
  echo "<th>Server</th>";
  echo "<th>Deployment</th>";
  echo "<th>URL</th>";
  echo "<th>Status</th>";
  echo "<th>Port</th>";
  echo "</tr>";
while($row = mysqli_fetch_array($result)){
  echo "<tr>";
  echo "<td>" . $row['server'] . "</td>";
  echo "<td>" . $row['name'] . "</td>";
  echo "<td>" . $row['url'] . "</td>";
   $url = $row['url'];
   $port = $row['port'];
   $url = '$url';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_exec($ch);
$retcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if (200==$retcode) {
  echo "<td><span class='badge badge-success'>LIVE</span></td>";
} else {
  echo "<td><span class='badge badge-danger'>DOWN</span></td>";
}
  echo "<td>" . $row['port'] . "</td>";
  echo "</tr>";
}
// Free result set
mysqli_free_result($result);
} else{
  echo "No records matching your query were found.";
}
} else{
  echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
?>

$url='$url';

That line shouldn't be in there. And if it is in there it needs to be double quotes to work.

Single quotes and double quotes work very differently in php. Having a $variable wont work as you're expecting if it's surrounded by single quotes.

<?php
//Example of how php treats a string in double quotes
$strFirstName="John";
echo "$strFirstName";

?>

<?php
//Example of how php treats a string in single quotes
$strFirstName="John";
echo '$strFirstName';

?>

The first example will work as expected, but the second one will literally output '$strFirstName' instead of 'John'

As you simply need to determine if a particular url is active or not I'd be tempted to use get_headers ~ it's pretty quick

$url='https://www.google.com';
$headers = get_headers( $url, 1 );
$active = !empty( $headers );
if( $active ){/* do stuff */}

Or, put it in a function

function get_status( $url ){
    $headers = @get_headers( $url, 1 );
    return !empty( $headers );
}

$url = 'http://www.holycatflap.com';

$status = get_status( $url ) ? sprintf( '"%s" is UP!',$url ) : sprintf( '"%s" DOWN',$url );
printf("<pre>%s</pre>", $status );

outputs:

"http://www.holycatflap.com" DOWN