PHP 脚本执行内存使用大小

<?php
/*
php内存使用机制
Time 2014-06-04
*/
function convert($size)
{
        $unit = array('b','kb','mb','gb','tb','pb');
        return round($size/pow(1024,($i=floor(log($size,1024)))),2).' '.$unit[$i];
}

function curl_post($url, array $post = array(), array $options = array())
{
        $defaults = array(
                        CURLOPT_POST => 1,
                        CURLOPT_HEADER => 0,
                        CURLOPT_URL => $url,
                        CURLOPT_FRESH_CONNECT => 1,
                        CURLOPT_RETURNTRANSFER => 1,
                        CURLOPT_FORBID_REUSE => 1,
                        CURLOPT_TIMEOUT => 4,
                        CURLOPT_POSTFIELDS => http_build_query($post)
        );

        $ch = curl_init();
        curl_setopt_array($ch, ($options + $defaults));
        if( ! $result = curl_exec($ch))
        {
                trigger_error(curl_error($ch));
        }
        curl_close($ch);
        return $result;
}

function start() {
        $array = array();
        for ($i = 1; $i <= 30; $i++) {
                $array[] = $i.'<orders>
    <order>
        <orderid>E00000000001</orderid>
        <callback>D_00001</callback>
        <customerid>761342</customerid>
        <mailno>1200000000001</mailno>
        <sender>
            <name>刘XX</name>
            <company>韵达快运</company>
            <city>上海市,青浦区</city>
            <address>盈港东路6679号</address>
            <postcode>201703</postcode>
            <phone>021-12345678</phone>
            <mobile>13812345678,13587654321</mobile>
        </sender>
        <receiver>
            <name>张YY</name>
            <company>缘港商务</company>
            <city>广东省,广州市,天河区</city>
            <address>帝王大厦5-12号</address>
            <postcode>510520</postcode>
            <phone>021-12345678</phone>
            <mobile>13587654321</mobile>
        </receiver>
        <sendstarttime>2010-06-19 08:00:00</sendstarttime>
        <sendendtime>2010-06-19 12:00:00</sendendtime>
        <weight>0.753</weight>
        <size>0.12,0.23,0.11</size>
        <value>126.50</value>
        <freight>8.00</freight>
        <premium>1.00</premium>
        <other_charges>0.00</other_charges>
        <collection_currency>CNY</collection_currency>
        <collection_value>155.50</collection_value>
        <special>0</special>
        <items>
            <item>
                <name>芭比闹钟</name>
                <number>1</number>
                <remark></remark>
            </item>
        </items>
        <remark>包已打好</remark>
    </order>
</orders>';
        }
        
        
        foreach ($array as $value) {
                $response = curl_post('http://127.0.0.1/demo/test/interface.php', array('data'=>$value));
        }
}

$i = 5;
while (true) {
        echo convert(memory_get_usage()) . "--s--\n";
        start();
        echo convert(memory_get_usage()) . "--e--\n";
        $i--;
        if ($i < 1) {
                break;
        }
}
?>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值