为fastCGI调用exit()函数时出错? [英] Errors when calling exit() function for fastCGI?

查看:96
本文介绍了为fastCGI调用exit()函数时出错?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在阅读人们在运行fastCGI时在其php脚本中使用退出功能时遇到的问题

I've been reading that people face problems when using the exit function in their php script while running fastCGI

https://serverfault.com/questions/84962/php-via -fastcgi通过呼叫退出终止

http://php.net/manual/en/function.exit.php

应该注意,如果构建一个在FastCGI上运行的站点,则调用exit将在服务器的日志文件中生成错误.这可以很快填满."

"It should be noted that if building a site that runs on FastCGI, calling exit will generate an error in the server's log file. This can quickly fill up."

但是,即使配置了fastCGI,运行此简单脚本后,我的错误日志也没有报告此问题:

However my error log isn't reporting this problem after running this simple script even though I have fastCGI configured:

<?php
$num=2;

if($num==2){
    exit();
}
?>

在配置了fastCGI的情况下使用退出功能是否安全? php中的退出功能还有其他选择吗?

Would it be safe to use the exit function while I have fastCGI configured? And are there any alternatives to the exit function in php?

我正在使用exit()函数进行表单验证(即,如果表单是有效的出口,如果没有将所有发布的变量解析到文本字段中).

I'm using the exit() function form form validation (ie if a form is valid exit, if not parse all the posted variables into the text fields.)

推荐答案

使用exit()与die()相同有一些合理的理由.一个示例是遵循标题Location:redirect.

There are a few legitimate reasons to use exit() which is the same as die(). One example would be to follow a header Location: redirect.

表单验证不是使用die()的地方.对代码进行结构化,以便您将函数或类与返回值的方法一起使用,并利用分支逻辑.

Form validation is not the place to use die(). Structure your code so that you utilize functions or classes with methods that return values instead, and utilize branching logic.

就fastcgi而言,如果在到达不应返回的代码的情况下适当使用了exit,则这些情况将是非典型的,并且一些日志消息也将不成问题.填满日志文件似乎是一个很愚蠢的理由,它不做任何事情-一个活动的Web服务器正在记录每个请求,没有人认为您不应该拥有Web日志.

In terms of fastcgi, if exit is used appropriately for situations where code is reached that should not be, then those situations will be atypical and a few log messages should not be a problem. Having a log file fill up seems a pretty silly reason not to do something -- an active webserver is logging every request and nobody argues that you shouldn't have a web log.

这篇关于为fastCGI调用exit()函数时出错?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆