0

我在本地计算机上运行 php,本地计算机上也有 heidisql。我只是在 digitalocean 上设置了一个服务器,并在上面安装了 mysql。当我运行时,我在本地机器上使用 PHP 运行查询,页面运行查询大约需要7.81几秒钟。当我将查询复制到 heidisql 中时,0.141运行相同的查询需要几秒钟。什么会导致 PHP 变慢?

注意:在我切换到数字海洋之前,php版本运行在1第二个左右,php没有变化。

这是我正在运行的 PHP:

$db = new Database();

$start = microtime(true);

$db->query("
set @miles = 10;

select
@lat := latitude,
@lon := longitude,
@city := accent,
@country := country,
#@region := region,
@city_id := cc.city_id
from cities cc
inner join countries c on cc.country_id = c.country_id
inner join regions r on cc.region_id = r.region_id and c.country_id = r.country_id
left join locations l on cc.city_id = l.city_id
where city = 'rosemount' and country = 'us' and r.region = 'mn'
limit 1;
");

$cities = $db->getAll("
SELECT c.city_id as id, 
accent as city, 
country as country, 
region, 
latitude, 
longitude,
distance(@lat, @lon, latitude, longitude) as `distance`,
direction(@lat, @lon, latitude, longitude) `direction`
FROM locations l
inner join cities c on l.city_id = c.city_id
inner join regions r on c.region_id = r.region_id
inner join countries cu on c.country_id = cu.country_id
WHERE MBRContains(
    LineString(
        Point(
            @lat + @miles / 68.703, 
            @lon + @miles / (68.703 / COS(RADIANS(@lat)))
        ), 
        Point(
            @lat - @miles / 68.703, 
            @lon - @miles / (68.703 / COS(RADIANS(@lat)))
        )
    ), location)
and l.city_id != @city_id
order By `distance`
");

echo "<p>" . round(microtime(true) - $start, 2) . "</p>";

echo "<pre>";
print_r($cities);
echo "</pre>";
4

0 回答 0