php 实现的 web service 效率问题

wf8010 2005-12-18 05:32:15
按照网上的教程试着写了个web service,实现的是客户端每次请求往服务端写一条数据到数据库,可是测试下来,同时开5个客户端,每个客户端用循环写1000条数据(不设延时),发现5个客户端都写完居然要30来分种,感觉是太慢了,请问有什么办法能提高服务端的处理速度呢?
...全文
287 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
uuq 2005-12-20
  • 打赏
  • 举报
回复
以前8848在线支付也用这个
uuq 2005-12-20
  • 打赏
  • 举报
回复
偶马上要做一个这个东东。
现在正在找资料。
还要分析xml文档。
wf8010 2005-12-19
  • 打赏
  • 举报
回复
哦,并不算慢,多谢多谢。这么说来WEB service 并不是狠适合用来做这个东西
Gdj 2005-12-19
  • 打赏
  • 举报
回复
我不是嘲笑他。只是开个玩笑。因为我觉得这帖迟早是要变成水帖的>:D。具体的时间xuzuning(唠叨) 已经写了。这个速度并不算慢。就算页面执行时间为0,打开一个页面总时间0.36也很正常。想更快的话可以考虑找个,或开发个不是用tcp协议的系统而不用web。
wf8010 2005-12-19
  • 打赏
  • 举报
回复
Server端代码:
<?php
require_once("nusoap.php");
$ns="http://bbox.mezimedia.com/blackbox3/google_Adwords/apility_1.0.0d/soap/nusoap";
$server = new soap_server();
$server->configureWSDL('LogService',$ns);
$server->wsdl->schemaTargetNamespace=$ns;

$server->register('log_debug',
array( 'timestamp' => 'xsd:string',
'module' => 'xsd:string',
'user'=>'xsd:string',
'operation'=>'xsd:string','message'=>'xsd:string',
'http_status_code'=>'xsd:string','refer_url'=>'xsd:string'
),
array('success' => 'xsd:string'),
$ns
);

function log_debug($timestamp,$module,$user,$operation,$message,$http_status_code='',$refer_url='')
{

$level="DEBUG";


if(!ereg("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})",$timestamp,$regs)){

return new soap_fault('Client','','Invalid log timestamp');

}elseif(!($module=='M1'||$module=='M2'||$module=='M3'||$module=='M4'||$module=='M5')){

return new soap_fault('Client','','Invalid log Module');

}elseif(!((strcasecmp($operation, '1') == 0)||(strcasecmp($operation, '2') == 0)||strcasecmp($operation, '3') == 0)){

return new soap_fault('Client','','Invalid log category');
}

elseif ($message==NULL || $message==' ')
{

return new soap_fault('Client','','message should not null');
}
elseif($user==NULL || $user==' '){
return new soap_fault('Client','','user name should not null');
}
else{
$fp=fopen("log_1020","a+");
$anum=1020;

$link = mysql_connect('web13', 'myuser', 'mypassword')
or die('Could not connect: ' . mysql_error());

mysql_select_db('BBoxV3_ImportData') or die('Could not select database');

$sql=" insert into log_message(level,timestamp,module,user,operation,message,http_status_code,referer_url) ";
$sql.=" values('$level','$timestamp','$module','$user','$operation','$message','$http_status_code','$refer_url') ";

$result = mysql_query($sql);

if(!$result)
{
echo $sql."\n";
echo 'Query has error: ' . mysql_errno() . ':' . mysql_error() . '\n';
mysql_close();
exit;
}

mysql_close();
fwrite($fp,$timestamp."\t".$module."\t".$user."\t".$operation."\t".$level."\t".$message."\t".$http_status_code."\t".$refer_url."\n");
fclose($fp);

$str=$timestamp."\t".$module."\t".$user."\t".$operation."\t".$level."\t".$message."\t".$http_status_code."\t".$refer_url."\n";
}

}

$server->service($HTTP_RAW_POST_DATA);

?>

client:

<?php
include('nusoap.php');
$wsdl="http://MyURL/server.php?wsdl";
$client=new soapclient($wsdl, 'wsdl');

$param=getparam(date("Y-m-d H:i:s"),'M5','guy','1','Here is some DEBUG');
$result = $client->call('log_debug', $param);

echo $result."\n";
echo "<xmp>".$client->request."</xmp>";
echo "<xmp>".$client->response."</xmp>";

// 用来转换成数组
function getparam($timestamp,$module,$user,$operation,$message,$http_status_code='',$refer_url='',$level='DEBUG')
{
$arr=array('timestamp'=>$timestamp,
'module'=>$module,
'level'=>$level,
'user'=>$user,
'operation'=>$operation,
'message'=>$message,
'http_status_code'=>$http_status_code,
'refer_url'=>$refer_url
);

return $arr;

}
?>

恳请各位帮忙分析一下,多谢
xuzuning 2005-12-19
  • 打赏
  • 举报
回复
30分钟是1800秒
5个用户每个1000次共计5000次
平均每次0.36秒,考虑到申请连接的时间应该不算慢了
tovy 2005-12-19
  • 打赏
  • 举报
回复
~~~~~~~
:)
ashchen 2005-12-19
  • 打赏
  • 举报
回复
按照网上的教程试着写了个web service

用的socket?
wf8010 2005-12-19
  • 打赏
  • 举报
回复
用服务器做client,5进程。
pswdf 2005-12-19
  • 打赏
  • 举报
回复
发一部分代码出来,分析一下
Cain 2005-12-19
  • 打赏
  • 举报
回复
这是你自身写的代码有问题啊,不信你可以做一下单个用户的测试
gu1dai 2005-12-19
  • 打赏
  • 举报
回复
楼上的就不用嘲笑他了。

你的客户端是用xmlhttp还是服务器端的client?
「已注销」 2005-12-19
  • 打赏
  • 举报
回复
呵呵,唠叨老大好像算错了。
呵呵

5个同时,总共时间是30分钟。

最后一个完成时,他自身总共用了30分钟。

因此,对于他来说,平均每条记录耗时1.8秒

可以在客户端、服务器端打印时间消耗出来看看,实际上,每次用php函数做数据库操作时的时间消耗都只是0.00xx秒,而在创建服务 $client=new soapclient($wsdl, 'wsdl'); 和 远程调用方法 $result = $client->call('log_debug', $param);
时花去了大量时间,

而如果你的客户端与服务器端都在一台机器上或者在局域网内,保障网络连接速度的话,那么每次的创建连接,调用也就是0.1x秒,这样的话,一次操作也就是0.3秒左右,而如果你创建一次连接,然后循环调用的话,那么平均每次操作时间在0.15秒左右。

忽略多个socket连接,多数据库连接的影响的话

需要的时间最小大概是
2.5分钟。

呵呵,不过,webservice并不适合 客户端特多, 操作特频繁的应用,建立连接花费时间太多

(这个时间的花费主要是webservice实现自身的xml部分所影响,socket影响不大(嘿嘿,我自己瞎说的,随便看看就好,嘿嘿))。
gu1dai 2005-12-19
  • 打赏
  • 举报
回复
你比较过.net做的web service的速度吗?
一定要切身比较过才好发表意见阿。
Gdj 2005-12-18
  • 打赏
  • 举报
回复
按照网上的教程试着写了个asp web service,实现的是客户端每次请求往服务端写一条数据到数据库,可是测试下来,同时开5个客户端,每个客户端用循环写1000条数据(不设延时),发现5个客户端都写完居然要80来分种,感觉是太慢了,请问有什么办法能提高服务端的处理速度呢?

21,891

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧