用另一个php文件执行php文件

时间:2011-08-02 05:18:11

标签: php mysql linux

我想使用exec()函数通过另一个php doc执行php doc。我的代码在我的本地设置上工作但由于某种原因它在我的远程设置上失败。

如果我直接在命令行php /home/user/domains/sitename/public_html/testing/doc1.phpphp /home/user/domains/sitename/public_html/testing/doc2.php testing中输入命令作为任何用户,它执行正常,我看到一个新的数据库条目。如果我直接从浏览器运行doc1,它就会失败。

文件夹是权限755,php文档是644。

有人有什么想法吗?

Doc 1

exec('php /home/user/domains/sitename/public_html/testing/exec_test.php testing');

上面目录中的文档2

include("/home/user/domains/sitename/public_html/connection_dir/connection.php");
$db = new PDOConnectionFactory();
$conn = $db->getConnection();

//prepare for utf8 characters
$sql = 'SET NAMES utf8';
$stmt = $conn->prepare($sql);
$result=$stmt->execute();

$sql = 'SET CHARACTER SET utf8';
$stmt = $conn->prepare($sql);
$result=$stmt->execute();
//**************************

$test=$argv[1];

 $sql = 'INSERT INTO video
(field1, field2, field3, field4, field5, field6) VALUES(?,?,?,?,?,?)';
$stmt3 = $conn->prepare($sql);
$result=$stmt3->execute(array('','',$test,'','untitled','1'));

2 个答案:

答案 0 :(得分:2)

使用passthru()http://www.php.net/manual/en/function.passthru.php)执行命令,这样您就能看到引发的错误

答案 1 :(得分:2)

php可执行文件可能不在$PATH中。指定php解释器的完整路径,即/usr/bin/php

此外,如果您没有充分的理由使用exec,只需include该文件。