只是为了好玩,我试图让从PHP CLI(在/ usr/bin中/ PHP的-a)wget的下载和它的作品:为什么wget backticks shell命令在PHP CLI中工作,而不是在PHP脚本中工作?
php > `wget -q -nd -O /Users/user/path/to/file.html http:\/\/host.com/some_file.html`;
php > // a HTML file is downloaded and its content is placed into /Users/user/path/to/file.html
然而,当我尝试从PHP脚本做同样的事情,这是行不通的:
<?php
`wget -q -nd -O /Users/user/path/to/file.html http:\/\/host.com/some_file.html`;
// After requesting the script from the browser and after the script is executed, the file doesn't exist on the specified path
我想说的是,其执行的Apache,因此PHP服务器端脚本的用户是一样的,其在命令行中执行PHP命令的用户(所以我想这不应该是权限问题)。
为什么如果我使用.php脚本并在脚本中调用wget文件没有保存?
感谢您的关注!
PS:请不要告诉我,我可以用卷曲对于这样的任务,我知道我可以,我只是好奇,想知道我可以做同样的事情,而不使用PHP工具,这是它
PHP日志中是否有错误? – Barmar 2014-12-27 16:04:11
也许'wget'不在apache用户的'$ PATH'中? – Barmar 2014-12-27 16:05:04
@Barmar不,在php错误日志中没有任何错误,我已经检查过'wget'应该在路径中,因为apache用户和我用来运行'php' CLI命令的用户是一样的 – tonix 2014-12-27 16:07:13