doupaoyan6083 2012-06-04 11:23
浏览 30
已采纳

PHP shell脚本和MAMP上的PHP之间的区别?

This is weird to me. I wonder why. I wrote a PHP script to validate syntax of another PHP script named test.php

 <?php
    print("Hello World");
    ?>

The validating script index.php is:

#!/usr/bin/env php
<?php
exec("php -l test.php", $error, $retcode);
echo($retcode . "<br />");
var_dump($error);
?>

When I run on command line php index.php, it generates this output:

0<br />array(1) {
  [0]=>
  string(37) "No syntax errors detected in test.php"
}

This looks good to me. However, when I run on localhost it generates this output:

#!/usr/bin/env php 5
array(0) { }

Why $retcode is set to 5? Also, I'm on PHP5.3

  • 写回答

1条回答 默认 最新

  • dongluni0568 2012-06-04 13:50
    关注

    Okay, I already figured this out.

    Check http://linux.die.net/man/1/rsync for exit code info.

    The problem is that I have to use the PHP interpreter on MAMP, which is:

    exec("/Applications/MAMP/bin/php/php5.3.6/bin/php -l $file",$error,$retcode);
    

    The one I used before was PHP interpreter on OS X.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?