从网页运行PHP CLI脚本(Run a PHP CLI script from a webpage)
我有一个(可能是愚蠢的)问题。 我有一个PHP脚本,用于cli使用。 当我从命令行运行它时工作正常,没有问题。 问题是我正在使用的网站对主机服务器有ssh限制,我无法在那里运行ssh。 因此我的问题是:我如何从另一个可以通过网络访问的php运行脚本? 已经尝试使用exec(),system()等。主要问题是我需要他$ _SERVER ['SHELL']变量集,并且当调用来自web浏览器当然php不会设置它。
任何ideeas将大大优于,thanx。
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.
原文:https://stackoverflow.com/questions/4969250
最满意答案
这里是Stroustrup的介绍: C ++风格和技术常见问题
在C ++中,
NULL
的定义是0,所以只有一个审美的差异。 我更喜欢避免宏,所以我使用0.另一个NULL
问题是人们有时错误地认为它不同于0和/或不是一个整数。 在标准前的代码中,NULL
有时被定义为不合适的东西,因此必须/必须避免。 这几天并不常见。如果你必须命名空指针,调用它为
nullptr
; 这就是C ++ 11中所说的。 那么,nullptr
将是一个关键字。也就是说,不要出现小东西。
Here's Stroustrup's take on this: C++ Style and Technique FAQ
In C++, the definition of
NULL
is 0, so there is only an aesthetic difference. I prefer to avoid macros, so I use 0. Another problem withNULL
is that people sometimes mistakenly believe that it is different from 0 and/or not an integer. In pre-standard code,NULL
was/is sometimes defined to something unsuitable and therefore had/has to be avoided. That's less common these days.If you have to name the null pointer, call it
nullptr
; that's what it's called in C++11. Then,nullptr
will be a keyword.That said, don't sweat the small stuff.
相关问答
更多-
为什么指针可以为NULL(Why can pointers be NULL)[2023-10-11]
常数0的解释取决于上下文。 如果它在需要数字的上下文中使用,则为零。 如果它在需要指针的上下文中使用,则将其视为空指针。 所以如果你有代码: int n = 0; // assigns zero int *p = 0; // assigns null pointer somefunc((char *)0); // passes null pointer to the function 在C中,允许宏NULL扩展为整数常量0或这样的常量强制转换为void * 。 在C ++ pre-11中,它可以扩展为一个 ... -
根据我的经验, if (ptr)或if (!ptr)形式的测试是首选的。 它们不依赖于符号NULL的定义。 他们不会暴露意外任务的机会。 他们清晰简洁。 编辑:由于SoapBox在注释中指出,它们与C ++类(例如auto_ptr兼容,它们是作为指针的对象,它们提供了一个转换为bool来完全实现这个习语。 对于这些对象,与NULL的显式比较将不得不调用对指针的转换,这可能具有其他语义副作用,或者比bool转换意味着的简单存在检查更昂贵。 我喜欢代码,说明没有不需要的文字是什么意思。 if (ptr != N ...
-
回到C ++ 03,空指针由ISO规范(§4.10/ 1)定义为 空指针常量是计算为零的整数类型的积分常量表达式(5.19)rvalue。 这就是为什么在C ++中你可以写 int* ptr = 0; 在C中,这个规则是相似的,但有点不同(§6.3.2.3/ 3): 值为0的整数常量表达式,或者转换为void *类型的表达式称为空指针常量.5)如果将空指针常量转换为指针类型,则生成的指针(称为空指针)为保证比较不等于指向任何对象或函数的指针。 因此,两者 int* ptr = 0; 和 int* ptr ...
-
这里是Stroustrup的介绍: C ++风格和技术常见问题 在C ++中, NULL的定义是0,所以只有一个审美的差异。 我更喜欢避免宏,所以我使用0.另一个NULL问题是人们有时错误地认为它不同于0和/或不是一个整数。 在标准前的代码中, NULL有时被定义为不合适的东西,因此必须/必须避免。 这几天并不常见。 如果你必须命名空指针,调用它为nullptr ; 这就是C ++ 11中所说的。 那么, nullptr将是一个关键字。 也就是说,不要出现小东西。 Here's Stroustrup's t ...
-
当在c ++中传递一个指针(即foo(some_object* p) )时,你实际上传递了指针的值,即对象所在的位置。 值本身是一个副本,这意味着如果你做p = NULL; 在你的函数里面,它不会改变原来的指针,但是它指向的地址保存了同一个原始对象。 例: #include
using namespace std; class obj{ public: int a; }; void foo(obj* pp){ pp->a = 2; pp = NULL; ... -
对于指针, p和(p != 0)完全相同。 如果它给你一个段错误,那么它不是一个简单的指针,或者问题在其他地方 For a pointer, p and (p != 0) are exactly equivalent. If it gives you a segfault, then either it's not a plain pointer, or the problem is elsewhere
-
这是不好的做法,原因如下: 在析构函数中将指针设置为null可能会掩盖双重破坏问题。 良好的做法是尽早发现问题。 在delete指针之前检查指针是否只会增加不必要的代码。 delete通过什么都不做来处理空指针。 好的做法是尽量减少代码量。 This is bad practice for the following reasons: Setting a pointer to null in the destructor may mask double destruction problem. Good p ...
-
通过说int *ptr = NULL; 你说的是“我正在声明一个名为ptr的int指针,我想指向位置0 ( NULL )。这就是它所说的。 现在,如果您尝试读取或写入ptr您将得到未定义的行为 ,这通常是一个可怕的地方(比仅仅得到错误更糟糕,因为您的程序可能开始在其他地方遇到问题而您不知道为什么) 。 但通常,当您想要表示不应该使用NULL指针并且必须初始化时,会使用NULL指针。 正如大卫施瓦茨所说, 如果使用int* ptr而不是int *ptr ,将更容易理解。 这是因为ptr的类型实际上是int* ...
-
c ++设置空指针?(c++ set null pointers?)[2023-10-07]
以下是将其设置为NULL - 将其定义为不同的类型: LookupTable* table = NULL; 如果您习惯于处理C#,那么您可能会将类视为“值类型”。 这也可能与您的想法不同。 在C ++中: LookupTable table1; LookupTable table2 = table; 编辑table2时,table1不会更改。 和: void SomeFunction(LookupTable t) { ... -
在C ++ 03中,比ptr = NULL更喜欢ptr = 0 (Bjarne S.说,阅读下面引自他的网站的摘录) 在C ++ 0x中, ptr = nullptr (请参阅此 ) Bjarne Stroustrup说 , 我应该使用NULL还是0? 在C ++中,NULL的定义是0,所以只存在美学差异。 我宁愿避免使用宏,所以我使用0. NULL的另一个问题是人们有时会错误地认为它不同于0和/或不是整数。 在预标准代码中,NULL有时被定义为不适合的东西,因此必须避免。 这些日子不太常见。 如果您必须命 ...