【问题标题】:How to open cache on failed mysql connection?如何在失败的mysql连接上打开缓存?
【发布时间】:2014-09-11 16:19:16
【问题描述】:

我连接到 MySQL 为我的网站获取动态内容的数据。但是,如果我的远程数据库服务器出现故障,我如何向访问者显示网页缓存或替换?

我目前的尝试是从我的远程 FTP 服务器加载页面。我会实例化一个尝试连接到数据库的类:

        public function __construct($cached)
    {
        $this->con = mysql_connect($host, $user, $pass, $data);

        // if we cannot open a connection to mysql then use ftp
        if (! $this->con)
        {
            fopen("ftp://" . $ftpuser . ":" . $ftppass . "@" . $ftpserv . $cached, "r");

            return;
        }

        mysql_select_db($data, $this->con);
    }

某事失败了

fopen(...)

并且页面不会像服务器启动时那样包含数据。但是,我测试了包含的字符串,它可以工作。

我该如何解决这种尝试,或者一般来说,我的问题的最佳解决方案是什么?

【问题讨论】:

    标签: php html mysql caching connection


    【解决方案1】:

    我修好了。

            $obj = file_get_contents("ftp://" . $ftpuser . ":" . $ftppass . "@" . $ftpserv . $dir, "r");
    
        echo $obj;
    

    我用过

    file_get_contents()
    

    并回显整个页面。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-01-07
      • 2017-04-23
      • 2016-05-06
      • 1970-01-01
      • 1970-01-01
      • 2013-08-12
      • 2011-12-08
      • 1970-01-01
      相关资源
      最近更新 更多