开发者

execute php document with another php document

开发者 https://www.devze.com 2023-03-25 10:31 出处:网络
I want to execute a php doc through another php doc using the exec开发者_如何学JAVA() function. The code I have works on my local setup but for some reason it fails on my remote setup.

I want to execute a php doc through another php doc using the exec开发者_如何学JAVA() function. The code I have works on my local setup but for some reason it fails on my remote setup.

If I type the command directly in the command line php /home/user/domains/sitename/public_html/testing/doc1.php or php /home/user/domains/sitename/public_html/testing/doc2.php testing as any user, it executes fine and I see one new database entry. If I run doc1 directly from the browser it fails.

Folders are permission 755 and php docs are 644.

Anyone have any ideas?

Doc 1

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

Doc 2 in above directory

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'));


The php executable is probably not in $PATH. Specify the full path to your php interpreter, i.e. /usr/bin/php.

Also if you don't have a good reason to use exec, just include the file.


Use passthru() ( http://www.php.net/manual/en/function.passthru.php ) to execute command so you will be able to see what errors are thrown

0

精彩评论

暂无评论...
验证码 换一张
取 消