For my homework, we have 3 websites. Each website has a webpage where we use PHP to dislay a users table from our mysql database. We then must use CURL (required to use CURL) to have a webpage that displays users table from ALL 3 websites.
Below is my code.
For my users list, I simply use PHP to connect to my mysql database and echo out the users table.
For the other 2 websites users list, I use CURL.
However, the professor says that it takes too long to load (takes about 4 seconds I guess)
What should i change in my code or any suggestions as to how to implement this (must use CURL to get other 2 websites users list) and make it faster? Thanks!
<?php
echo "<br>";
echo "<br>";
$conn = mysqli_connect("login.ipagemysql.com", "username", "password", "user_website");
if (!$conn) {
die("Could not connect: " . mysqli_error($conn));
}
//check comment
$sql = "SELECT First_Name, Last_Name, Email, Address, Home_Phone, Cell
FROM Users
";
if($result = mysqli_query($conn, $sql)){
if(mysqli_num_rows($result) > 0){
echo "<table>";
echo "<tr>";
echo "<th> First_Name </th>";
echo "<th> Last_Name </th>";
echo "<th> Email </th>";
echo "<th> Address </th>";
echo "<th> Home_Phone </th>";
echo "<th> Cell_Phone </th>";
echo "</tr>";
while($row = mysqli_fetch_array($result)){
echo "<tr>";
echo "<td>" . $row['First_Name'] . "</td>";
echo "<td>" . $row['Last_Name'] . "</td>";
echo "<td>" . $row['Email'] . "</td>";
echo "<td>" . $row['Address'] . "</td>";
echo "<td>" . $row['Home_Phone'] . "</td>";
echo "<td>" . $row['Cell'] . "</td>";
echo "</tr>";
}
echo "</table>";
// 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($conn);
}
?>
<br>
<br>
<br>
Website 2 User's List
<?php
echo "<br>";
echo "<br>";
$ch = curl_init("http://website2.com");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$page = curl_exec($ch);
preg_match('#<table[^>]*>(.+?)</table>#is', $page, $matches);
foreach ($matches as &$match) {
$match = $match;
}
echo '<table>';
echo $matches[1] ;
echo '</table>';
curl_close($ch);
?>
<br>
<br>
<br>
Website 3 Users List
<?php
echo "<br>";
echo "<br>";
$ch = curl_init("http://website3.com");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$page = curl_exec($ch);
preg_match('#<table[^>]*>(.+?)</table>#is', $page, $matches);
foreach ($matches as &$match) {
$match = $match;
}
echo '<table>';
echo $match ;
echo '</table>';
curl_close($ch);
?>