• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

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

php 搞代码 3年前 (2022-01-23) 31次浏览 已收录 0个评论
文章目录[隐藏]

<?php

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

?>

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

回复内容:

<?php

<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 verif<p>5本文来源gao!daima.com搞$代!码#网#</p><pre>搞代gaodaima码

ication 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.

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

-1到底啥意思呢?

500M的文件?超时了吧


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:php 为什么执行 shell 返回值为 1?

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址