在Apache下连接到mssql时的PHP超时 [英] PHP timeout when connecting to mssql under apache
问题描述
PHP版本5.4, Apache版本2.4, CentOS 7.3
PHP Version 5.4, Apache Version 2.4, CentOS 7.3
尝试使用以下php代码连接到mssql db,当我从命令行运行它时,它可以正常工作.但是,当我将代码放在apache下(在同一服务器上)并通过浏览器调用时,出现超时错误.
Trying to connect to mssql db using the following php code which works fine when I run it from the command line. However, when I place code under apache (on same server) and call through browser I get a timeout error.
错误:连接失败:SQLSTATE [HYT00] SQLConnect:0 [unixODBC] [Microsoft] [SQL Server的ODBC驱动程序13]登录超时 过期+
Error: Connection failed: SQLSTATE[HYT00] SQLConnect: 0 [unixODBC][Microsoft][ODBC Driver 13 for SQL Server]Login timeout expired+
set_time_limit(30);
echo "+ Connection\n";
try {
$pdo = new PDO("odbc:sqlsrv_msodbc", "username", "password");
} catch (PDOException $e) {
echo 'Connection failed: ' . $e->getMessage();
}
推荐答案
我只是遇到了同样的问题.我正在无所事事地使用CentOS 7.3,并通过禁用SELinux来解决了这个问题.
I just had the same issue. I am using CentOS 7.3 in vagrant and solved it by disabling SELinux.
如果您处于开发环境中,并且禁用SELinux很酷,则可以通过以下方式实现:
If you're on a dev environment and disabling SELinux is cool you can do it by:
sudo vi /etc/sysconfig/selinux
设置
SELINUX=disabled
我在serverfault上找到了它: https://serverfault. com/questions/240015/how-do-i-allow-mysql-connections-through-selinux
I found this over at serverfault: https://serverfault.com/questions/240015/how-do-i-allow-mysql-connections-through-selinux
这篇关于在Apache下连接到mssql时的PHP超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!