Heim >Backend-Entwicklung >PHP-Tutorial >php 为什么执行 shell 返回值为 1?

php 为什么执行 shell 返回值为 1?

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-06 13:52:121415Durchsuche

<code>$cmd = system("wget http://la-lg.hostus.us/500MB.test",$r);
echo $r;</code>

?>

能成功执行,但是打印的数值是1,按道理来说正常不是1吗?只有错误才会别的

回复内容:

<code>$cmd = system("wget http://la-lg.hostus.us/500MB.test",$r);
echo $r;</code>

?>

能成功执行,但是打印的数值是1,按道理来说正常不是1吗?只有错误才会别的

我们看下官方文档的说法:

成功则返回命令输出的最后一行, 失败则返回 FALSE

再看看英语版:

Returns the last line of the command output on success, and FALSE on failure.

实际上,这两种说法都容易引起歧义,正确的理解应该是
成功则返回命令的退出码

<code>exit(code)</code>

中的code
大部分情况下,exit(0)代表没有错误。然而这并不代表所有。
具体的需要在对应命令下man wget
以下是结果:

<code>EXIT STATUS
       Wget may return one of several error codes if it encounters problems.
       0   No problems occurred.

       1   Generic error code.

       2   Parse error---for instance, when parsing command-line options, the .wgetrc or .netrc...

       3   File I/O error.

       4   Network failure.

       5   SSL verification failure.

       6   Username/password authentication failure.

       7   Protocol errors.

       8   Server issued an error response.

       With the exceptions of 0 and 1, the lower-numbered exit codes take precedence over higher-numbered ones, when
       multiple types of errors are encountered.
</code>

所以等于0确实是代表成功,而等于1代表了出错。
你的文件真的下载成功了吗?

-1到底啥意思呢?

500M的文件?超时了吧

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn