按照网上的教程试着写了个asp web service,实现的是客户端每次请求往服务端写一条数据到数据库,可是测试下来,同时开5个客户端,每个客户端用循环写1000条数据(不设延时),发现5个客户端都写完居然要80来分种,感觉是太慢了,请问有什么办法能提高服务端的处理速度呢?
解决方案 »
- 高手帮看下应该怎么写分页啊?
- 问一个问题 不知道是不是问题 ,就是CSDN forumID=c5eca554-e88a-47bd-873d-58c8014f2f91 后面这一串字符,有什么用
- 空白页麻烦会的近来看下
- 我在美国有一台服务器apache+php+mysql+mail。寻创业点子。
- mysql数据库后台表关联问题
- 求一条查询语句,谢谢!
- PHP中GD作图时汉字的输出问题?
- 求助~ 小弟的毕业论文
- 请问MYSQL中enum类型如何禁止NULL值插入?
- <input type=file>时会出现一个文本框和一个按钮,如何不要文本框而只留下按钮?
- 招PHP程序员 工作地 济南
- php中脚本文件错误,但WEB不报错
<?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;
}
?>恳请各位帮忙分析一下,多谢
一定要切身比较过才好发表意见阿。
呵呵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影响不大(嘿嘿,我自己瞎说的,随便看看就好,嘿嘿))。
现在正在找资料。
还要分析xml文档。