$_REQUEST, $_GET 和 $_POST 哪个最快? [英] Among $_REQUEST, $_GET and $_POST which one is the fastest?
问题描述
这些代码中哪个会更快?
Which of these code will be faster?
$temp = $_REQUEST['s'];
或
if (isset($_GET['s'])) {
$temp = $_GET['s'];
}
else {
$temp = $_POST['s'];
}
推荐答案
$_REQUEST
,默认包含$_GET
、$_POST
和$_COOKIE
的内容.
但这只是一个默认值,这取决于variables_order
;并且不确定是否要使用 cookie.
But it's only a default, which depends on variables_order
; and not sure you want to work with cookies.
如果非要我选,我可能不会用$_REQUEST
,我会选择$_GET
或$_POST
-- 取决于我的应用程序应该做什么 (即一个或另一个,但不是两个):一般来说:
If I had to choose, I would probably not use $_REQUEST
, and I would choose $_GET
or $_POST
-- depending on what my application should do (i.e. one or the other, but not both) : generally speaking :
- 当有人从您的应用请求数据时,您应该使用
$_GET
. - 当有人将(插入或更新;或删除)数据推送到您的应用程序时,您应该使用
$_POST
.
- You should use
$_GET
when someone is requesting data from your application. - And you should use
$_POST
when someone is pushing (inserting or updating ; or deleting) data to your application.
无论哪种方式,性能都不会有太大差异:与脚本的其余部分相比,差异可以忽略不计.
Either way, there will not be much of a difference about performances : the difference will be negligible, compared to what the rest of your script will do.
这篇关于$_REQUEST, $_GET 和 $_POST 哪个最快?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!