Curling和PHP来显示网站页面表的加载时间太长

时间:2019-05-01 00:21:53

标签: php html sql curl

对于我的作业,我们有3个网站。每个网站都有一个网页,我们在其中使用PHP从我们的mysql数据库中放置一个用户表。然后,我们必须使用CURL(必须使用CURL)才能创建一个显示所有3个网站的用户表的网页。

下面是我的代码。

对于我的用户列表,我只使用PHP连接到我的mysql数据库并回显出users表。

对于其他2个网站的用户列表,我使用CURL。

但是,教授说加载时间太长(我估计大约需要4秒钟)

我应该在代码中进行哪些更改或有关如何实现此建议的任何建议(必须使用CURL来获取其他2个网站的用户列表)并使之更快?谢谢!

<?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);

?>


0 个答案:

没有答案