获取PHP中http请求的字节大小

获取PHP中http请求的字节大小,php,api,post,httpcontext,Php,Api,Post,Httpcontext,您好,我目前正在进行商户账户系统的集成 我需要获取发送到我站点上的url的http请求中的totalbytes。我的网站是用PHP编写的 在C#中,它的工作原理如下:但要提到的主要一点是,我将如何在PH中做到这一点,因为似乎找不到关于这一点的好文档。提前谢谢 public void ProcessRequest (HttpContext context) { context.Response.Buffer = true; string response = "";

您好,我目前正在进行商户账户系统的集成

我需要获取发送到我站点上的url的http请求中的totalbytes。我的网站是用PHP编写的

在C#中,它的工作原理如下:但要提到的主要一点是,我将如何在PH中做到这一点,因为似乎找不到关于这一点的好文档。提前谢谢

 public void ProcessRequest (HttpContext context) 
{
    context.Response.Buffer = true;

    string response = "";
    string sMethod = "POST";

    //sUrl holds the address to the Verify service, this is a service from AllCharge 
    // that verifies the signature on the notification. This makes sure that the notification
    // was sent by AllCharge.

    //Demo server - use this address during the integaration, remark this line when working
    // with the live server
    string sUrl = "http://demo.allcharge.com/Verify/VerifyNotification.aspx";

    //Live server - use this address when working with the live server, remark this line 
    // during the integration
    //string sUrl = "https://incharge.allcharge.com/Verify/VerifyNotification.aspx";

    Int32 nCount = context.Request.TotalBytes;
    string formParameters = System.Text.Encoding.UTF8.GetString(context.Request.BinaryRead(nCount));

}

我能想到的最好的是下面的php函数

function findKb($content){
$count=0;
$order = array("\r\n", "\n", "\r", "chr(13)",  "\t", "\0", "\x0B");
$content = str_replace($order, "12", $content);
for ($index = 0; $index < strlen($content); $index ++){
    $byte = ord($content[$index]);
    if ($byte <= 127) { $count++; }
    else if ($byte >= 194 && $byte <= 223) { $count=$count+2; }
    else if ($byte >= 224 && $byte <= 239) { $count=$count+3; }
    else if ($byte >= 240 && $byte <= 244) { $count=$count+4; }
}
return $count;
}
函数findKb($content){
$count=0;
$order=数组(“\r\n”、“\n”、“\r”、“chr(13)”、“\t”、“\0”、“\x0B”);
$content=str_replace($order,“12”,$content);
对于($index=0;$index如果($byte=194&&$byte=224&&$byte=240&&$byte我能想到的最好的方法就是下面的php函数

function findKb($content){
$count=0;
$order = array("\r\n", "\n", "\r", "chr(13)",  "\t", "\0", "\x0B");
$content = str_replace($order, "12", $content);
for ($index = 0; $index < strlen($content); $index ++){
    $byte = ord($content[$index]);
    if ($byte <= 127) { $count++; }
    else if ($byte >= 194 && $byte <= 223) { $count=$count+2; }
    else if ($byte >= 224 && $byte <= 239) { $count=$count+3; }
    else if ($byte >= 240 && $byte <= 244) { $count=$count+4; }
}
return $count;
}
函数findKb($content){
$count=0;
$order=数组(“\r\n”、“\n”、“\r”、“chr(13)”、“\t”、“\0”、“\x0B”);
$content=str_replace($order,“12”,$content);
对于($index=0;$index
$rqsize = (int) $_SERVER['CONTENT_LENGTH'];
已经有人问过类似的问题。

试试这个:

$rqsize = (int) $_SERVER['CONTENT_LENGTH'];
已经有人问过类似的问题了

$size
应该是请求的长度


$size
应该是请求的长度。

PHP是解释语言,要做到这一点相当困难,请尝试使用
内存获取使用
函数,下面是示例
http://it.php.net/manual/en/function.memory-get-usage.php

PHP是一种解释语言,要做到这一点相当困难,请尝试使用
memory\u get\u usage
函数,下面是示例
http://it.php.net/manual/en/function.memory-get-usage.php

我发现让我使用它的最好方法是使用:

$size = @file_get_contents('php://input');

谢谢大家的帮助!

我发现让我使用它的最好方法是使用:

$size = @file_get_contents('php://input');

谢谢大家的帮助!

您要找的是
$\u服务器['CONTENT\u LENGTH']
吗?您要找的是
$\u服务器['CONTENT\u LENGTH']
吗?您必须接受自己的答案,这样其他有此问题的人才能看到它。您必须接受自己的答案,这样其他有此问题的人才能看到它。