php 为什么执行 shell 返回值为 1?
阿神
阿神 2017-04-11 08:57:23
[PHP讨论组]

<?php

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

?>

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

阿神
阿神

闭关修行中......

全部回复(3)
天蓬老师

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

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

再看看英语版:

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

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

exit(code)

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

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.

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

高洛峰

-1到底啥意思呢?

ringa_lee

500M的文件?超时了吧

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号