1

I want to execute a php doc through another php doc using the exec() 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'));
3
  • 2
    have you tried putting the full path to php? could be the 'www' user doesn't have the same path as the users you have tested with Commented Aug 2, 2011 at 5:23
  • 1
    Use the &$output parameter of exec() to see what you get back. At a guess, I'd say you need to provide the full path to the php binary, eg /usr/bin/php Commented Aug 2, 2011 at 5:24
  • You boys were right. Boy I feel silly lol. Thanks a lot guys. Commented Aug 2, 2011 at 5:32

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

I did not include all my code. You are right in specifying the whole path and it worked. The only reason I am using exec is because the php doc is executed after an ffmpeg command which requires exec. It is conditional on &&. Thanks a lot cweiske. Appreciate it.
2

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.