从网页运行PHP CLI脚本 [英] Run a PHP CLI script from a webpage

查看:93
本文介绍了从网页运行PHP CLI脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个(可能是愚蠢的)问题。
我有一个用php编写的脚本,用于cli用法。当我从命令行运行它时,效果很好,没有问题。问题是我正在处理的网站在托管服务器上具有ssh限制,而我无法在其中使用SSH来运行它。因此,我的问题是:如何从可通过Web访问的另一个php运行脚本?已经尝试使用exec(),system()等。
主要问题是我需要设置$ _SERVER ['SHELL']变量,并且当调用来自Web浏览器时,当然php并没有。

I have a (possibly dumb) question. I have a script made in php, constructed for cli usage. Works fine when I run it from the command line, no problem there. The problem is that the site I'm working on has ssh restrictions on the hosting server and I cannot ssh there to run it. Hence my question: how can I run the script from another php that is web-accessible? Already tried with exec(), system(), etc. The main problem is that I need he $_SERVER['SHELL'] variable set, and when the call is comming from a web browser of course php doesn't set it.

任何想法都将被深深感动,谢谢。

Any ideeas will be greatly apreciated, thanx.

推荐答案

exec()和相关函数调用不起作用的可能性有很多。

There are many possibilities why exec() and related function calls are not working for you.


  • 您的虚拟主机没有PHP- CLI已安装。只是一个Web服务器模块

  • 您需要使用完整的php二进制文件路径,因为缺少像样的外壳环境。例如。 / usr / bin / php< script> 代替 php< script>

  • 您的网络主机已在非标准路径上安装了PHP-CLI(例如 / usr / local / bin / php / opt / php5 / php

  • 网络服务器用户无权访问php二进制文件

  • 等等。

  • Your webhost does not have PHP-CLI installed. Just a webserver module
  • You need to use the full path to the php binary for lack of a decent shell environment. E.g. /usr/bin/php <script> instead of php <script>.
  • Your webhost has installed PHP-CLI on a non-standard path (e.g. /usr/local/bin/php, or /opt/php5/php)
  • The webserver user does not have rights to access the php binary
  • Et cetera..

这篇关于从网页运行PHP CLI脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆