php - 什么是 Exit(integer) 以及如何在 PHP 中使用它

标签 php codeigniter exit-code

我对 C、C++ 或比 PHP 更低的级别一无所知。我看了一下 github 上的 Codeigniter 3 代码,发现它添加了 exit status code constants ,即我们可以这样做:

exit(EXIT_DATABASE) 表示 exit(8)exit(EXIT_UNKNOWN_CLASS) 表示 exit(5)

有什么区别

echo 'Configuration file not found';
exit(3);

只是

exit('找不到配置文件'); ?

在 php 中使用 exit(integer) 的目的是什么?它不打印任何东西,是吗?我也检查了 the docs和谷歌一些但仍然不清楚。 如何使用它?我可以从哪里获得这方面的引用?

谢谢。

最佳答案

它向调用者提示运行脚本的结果。

如果您使用 execsystem 运行脚本并且您需要根据运行脚本的结果采取不同的行为,这在 php 中可能很有用。

<?php
   $output = array();
   $error = null;
   exec("/path/to/php cleanData.php", $output, $error);
   if ($error){
       Logger::log($error, $output);
       die("Sorry I was Unable to Clean the Data\n");
   }

关于php - 什么是 Exit(integer) 以及如何在 PHP 中使用它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16986524/

相关文章:

php - CodeIgniter 和 PostgreSQL - 从返回 refcursor 的函数中检索数据

python - Python 中的退出代码

c++ - C++ 中结构的构造函数导致非零退出代码

javascript - 如何在jquery中通过图像上传发送文本输入值

php - 如何在不覆盖 codeigniter 中的其他 session 的情况下使用 session 向外键插入值?

php - 在订单电子邮件和订单编辑页面中显示复选框字段数据

bash - 抑制 stderr 控制台输出但在 Shell 中保留退出代码

php - 从数据库中获取数据时返回空数组

php - 带 www 和不带 www 的网站在 codeigniter 中对 baseurl 的作用不同

php - 在 Codeigniter 中写入一个数组来配置?