dream2891 2019-05-01 00:21
浏览 42

用于显示网站页面表的Curling和PHP需要很长时间才能加载

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

?>


  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 R语言Rstudio突然无法启动
    • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
    • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
    • ¥15 用windows做服务的同志有吗
    • ¥60 求一个简单的网页(标签-安全|关键词-上传)
    • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
    • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
    • ¥100 为什么这个恒流源电路不能恒流?
    • ¥15 有偿求跨组件数据流路径图
    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值