<?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;
}
}
?>
PHP 脚本执行内存使用大小
最新推荐文章于 2021-03-19 23:40:19 发布