关于OpenCart 后台(Dashboard)首页打开很慢的问题_已迁移

很久没有搞OpenCart了,昨天在群里面看到一个人反应,OpenCart 后台(Dashboard)首页打开很慢,大约9秒,其他任何页面都很快。不知道什么原因,于是我帮他解决了这个问题,这里随便记录一下问题解决的经过和思路。
首先我让它开启mysql的慢查询记录,因为后台首页有一个图表统计,以及订单和用户的等统计数据。可是结果他说并没有查询超过2秒的记录。看来不是mysql查询的问题。
然后我又让他用firebug看一下,哪个http请求的时间线最长,本来以为有外部请求的原因,结果发现就是route=common/home&token= 返回的一个ajax超时状态。于是我就去查看了admin/controller/common/home.php 的源码,也没有发现有什么外部的请求。
于是我就一个个查看ControllerCommonHome 中index方法中所有的$this->load->model,后来发现下面这段代码:

if ($this->config->get('config_currency_auto')) {
            $this->load->model('localisation/currency');

            $this->model_localisation_currency->updateCurrencies();
        }

admin/model/localisation/current.php看了一下源代码,果然里面有一段curl请求外部链接的代码:

public function updateCurrencies($force = false) {
		if (extension_loaded('curl')) {
			$data = array();

			if ($force) {
				$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "currency WHERE code != '" . $this->db->escape($this->config->get('config_currency')) . "'");
			} else {
				$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "currency WHERE code != '" . $this->db->escape($this->config->get('config_currency')) . "' AND date_modified < '" .  $this->db->escape(date('Y-m-d H:i:s', strtotime('-1 day'))) . "'");
			}

			foreach ($query->rows as $result) {
				$data[] = $this->config->get('config_currency') . $result['code'] . '=X';
			}

			$curl = curl_init();
			//就是这里了,看到木有
			curl_setopt($curl, CURLOPT_URL, 'http://download.finance.yahoo.com/d/quotes.csv?s=' . implode(',', $data) . '&f=sl1&e=.csv');
			curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

			$content = curl_exec($curl);

			curl_close($curl);

			$lines = explode("\n", trim($content));

			foreach ($lines as $line) {
				$currency = utf8_substr($line, 4, 3);
				$value = utf8_substr($line, 11, 6);

				if ((float)$value) {
					$this->db->query("UPDATE " . DB_PREFIX . "currency SET value = '" . (float)$value . "', date_modified = '" .  $this->db->escape(date('Y-m-d H:i:s')) . "' WHERE code = '" . $this->db->escape($currency) . "'");
				}
			}

			$this->db->query("UPDATE " . DB_PREFIX . "currency SET value = '1.00000', date_modified = '" .  $this->db->escape(date('Y-m-d H:i:s')) . "' WHERE code = '" . $this->db->escape($this->config->get('config_currency')) . "'");

			$this->cache->delete('currency');
		}
	}

看到了吧,它用curl抓取了yahoo的关于汇率的数据,结合这2段代码可以看出,其实它的功能就是打开这个页面的时候自动更新数据库中汇率数据。
到此问题找到原因了,那么解决的方法总结一下:

  1. 服务器PHP是否支持CURL扩展

  2. 服务器空间是否允许访问外部链接

  3. 可以关闭自动更新汇率(Dashboard>System>Setting>Your Store>edit>local>Auto Update Currency 选择No


转载于:https://my.oschina.net/Majw/blog/425636

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值