如何在同一时间运行多个php页面?

时间:2013-06-15 12:30:54

标签: php html mysql

你好,我想问一个问题,我怎么能在同一时间运行超过php页面:我的项目是显示期望时间总线到达站我用台式电脑作为屏幕显示结果,我有3个屏幕(三个站),我有2个总线发送坐标到MySQL数据库然后我有PHP页面从数据库中选择最后的坐标,并计算公交车和车站之间的距离,然后计算到达的时间, 然后将变量传递到另一个php页面以显示结果,我想在执行显示页面之前执行计算页面的某种方式,我有一个问题,我有一个结果所有站必须是不同的?帮助导致它是我的毕业项目,这是计算页面的代码:

    <html>
</html>
<?php
mysql_connect("localhost", "root", "") or die("Could not connect: " . mysql_error());
mysql_select_db("vts");
session_start();
function distance($stop_name,$gps_id,$lat1, $lon1, $lat2, $lon2,$flag_GPS1) { 
    $theta = $lon1 - $lon2; 
    $dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) +  cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta)); 
    $dist = acos($dist); 
    $dist = rad2deg($dist); 
    $miles = $dist * 60 * 1.1515;
    $timeToArrive = (($miles * 1.609344)*1000)/(40000/60);


    if($flag_GPS1 == 1){
        $timeToArrive = (($miles * 1.609344)*1000)/(40000/60); 
        if($timeToArrive == 0){
            mysql_query("UPDATE stops_position SET flag_GPS1=0 WHERE stop_name = '$stop_name'");
            $_SESSION['TimeToArrive'] = 'Arrive' ; }
        else{
            $_SESSION['TimeToArrive'] = $timeToArrive ;
            }
    }
    else{
        $result = mysql_query("SELECT latitude,longitude,full_Distance FROM bus_info WHERE gps_id = '$gps_id' ");
        $row = mysql_fetch_row($result);
        $latitude_center = $row[0];
        $longitude_center = $row[1];
        $full_Distance = $row[2];
        $theta = $lon1 - $longitude_center; 
        $dist = sin(deg2rad($lat1)) * sin(deg2rad($latitude_center)) +  cos(deg2rad($lat1)) * cos(deg2rad($latitude_center)) * cos(deg2rad($theta)); 
        $dist = acos($dist); 
        $dist = rad2deg($dist); 
        $miles = $dist * 60 * 1.1515;
        $journey_In_meters = ($miles * 1.609344)*1000;
        if($journey_In_meters == 0){            
            mysql_query("UPDATE stops_position SET flag_GPS1 = 1 WHERE stop_name = '$stop_name'");
            $theta = $longitude_center - $lon2; 
            $dist = sin(deg2rad($latitude_center)) * sin(deg2rad($lat2)) +  cos(deg2rad($latitude_center)) * cos(deg2rad($lat2)) * cos(deg2rad($theta)); 
            $dist = acos($dist); 
            $dist = rad2deg($dist); 
            $miles = $dist * 60 * 1.1515;
            $timeToArrive = ($miles * 1.609344*1000)/(40000/60);
            $_SESSION['TimeToArrive'] = $timeToArrive ;         
        }
        else{
        $theta = $lon1 - $lon2; 
        $dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) +  cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta)); 
        $dist = acos($dist); 
        $dist = rad2deg($dist); 
        $miles = $dist * 60 * 1.1515;
        $dis = $miles * 1.609344*1000;
        $DistanceToArrive = $full_Distance - $journey_In_meters ;
        $timeToArrive = $DistanceToArrive/(40000/60);
        $_SESSION['TimeToArrive'] = $timeToArrive ;                 
        }
    }
}

$result = mysql_query("SELECT gps_id,latitude,longitude FROM gps_position WHERE gps_id = '1' ORDER BY id_field DESC LIMIT 1");
    while($row = mysql_fetch_array($result)){
    $gps_id=$row['gps_id'];
    $lat1=$row['latitude'];
    $long1=$row['longitude'];
    $result = mysql_query("SELECT * FROM stops_position where stop_name = 'station3' ");
    while($row = mysql_fetch_array($result)){
    $stop_name=$row['stop_name'];
    $flag_GPS1=$row['flag_GPS1'];
    $lat2=$row['latitude'];
    $long2=$row['longitude'];
    $_SESSION['station'] = $stop_name ; 
    }
    distance($stop_name,$gps_id,$lat1, $long1,$lat2,$long2,$flag_GPS1); 
}
$result = mysql_query("SELECT coming_from,destination FROM bus_info WHERE gps_id = '1' ");
    $row = mysql_fetch_row($result);
    $Coming_from = $row[0];
    $Destination = $row[1];     
$_SESSION['coming_from'] = $Coming_from ;
$_SESSION['destination'] = $Destination ;




?>

1 个答案:

答案 0 :(得分:1)

我会使用PDO来设置你的sql连接和预备语句,因为你调用数据的方式是一个安全问题。另外,我会使用jQuery Ajax在你需要的时候调用那些不同的页面。除非,它就像Eineki所说的那样简单,使用include或require语句来导入这些文件。