我有一个脚本可以进行 2-3 次数据库查询、2 次插入和 1 次更新。我遇到的问题是,当我通过访问 Web 服务器页面手动测试脚本时www.domain.com/handler.php?a=1&b=2&c=3
,我完美地获得了 3 个更新。但是当我使用这个功能时,它不起作用......更具体地说,INSERT INTO 不起作用。我在数据库中得到了很好的更新!但是没有新的条目。
while (($data = fgetcsv(STDIN)) !== false){
$url='http://domain.com';
$date = date('Y-m-d');
$type = trim($data[0]);
if ($type != ''){
$send_date = $data[2];
$email = $data[4];
$status = $data[7];
$error = $data[8];
$bounce = $data[10];
$ip = $data[14];
$job_id = $data[19];
$params = 'pmta_token='.$pmta_token.'&type='.$type.'&send_date='.$send_date.'&email='.$email.'&status='.$status.'&error='.$error.'&bounce='.$bounce.'&ip='.$ip.'&job_id='.$job_id;
$params= array('server'=>$_SERVER['SERVER_NAME'],'type'=>$data[0],'time'=>$data[1],'message'=>$data[8],'bouncecat'=>$data[10],'jobid'=>$data[19],'domip'=>$data[21]);
$line = $type.','.$email.','.$ip.','.$status.','.$error.','.$bounce.','.$job_id.','.date('c')."\n";
curl_post_async($url, $params);
}
}
function curl_post_async($url, $params){
foreach($params as $key => $val){
if (is_array($val)) $val = implode(',', $val);
$post_params[] = $key.'='.urlencode($val);
}
$post_string = implode('&', $post_params);
$parts=parse_url($url);
$fp = fsockopen($parts['host'],
isset($parts['port'])?$parts['port']:80,
$errno, $errstr, 30);
$out = "POST ".$parts['path']." HTTP/1.1\r\n";
$out.= "Host: ".$parts['host']."\r\n";
$out.= "Content-Type: application/x-www-form-urlencoded\r\n";
$out.= "Content-Length: ".strlen($post_string)."\r\n";
$out.= "Connection: Close\r\n\r\n";
if (isset($post_string)) $out.= $post_string;
fwrite($fp, $out);
fclose($fp);
}
我肯定错过了什么!我使用这个函数而不是 curl 的原因是因为 curl 需要花费时间连接和等待响应......这个脚本每分钟处理大约 2,000 个请求。
这是handler.php
这是失败并且没有在数据库中输入任何内容的那个,当我手动执行时没有错误,它就像一个魅力,但使用套接字失败,仅在插入时,更新通过套接字连接工作。? ?.?
mysql_connect('localhost','root','');
mysql_select_db('analyzer');
date_default_timezone_set('America/Los_Angeles');
if(isset($_POST['type'])){
$domip = @explode('/',$_POST['domip']);
$server = @strtolower($_POST['server']);
$type = @$_POST['type'];
$time = @$_POST['time'];
$message = @$_POST['message'];
$bouncecat = @$_POST['bouncecat'];
$jobid = @$_POST['jobid'];
$domain = @$domip[0];
$md5 = @$_POST['md5'];
$ip = @$domip[1];
if(isset($_POST['ip'])){$ip=$_POST['ip'];}
}else{
$domip = @explode('/',$_REQUEST['domip']);
$server = @strtolower($_REQUEST['server']);
$type = @$_REQUEST['type'];
$time = @$_REQUEST['time'];
$message = @$_REQUEST['message'];
$bouncecat = @$_REQUEST['bouncecat'];
$jobid = @$_REQUEST['jobid'];
$domain = @$domip[0];
$md5 = @$_REQUEST['md5'];
$ip = @$domip[1];
}
$now=date('Y-m-d H:i');
@mysql_query("INSERT INTO `log` (`type`,`time`,`message`,`cat`,`jobid`,`domain`,`ip`,`server`) VALUES('$type','$time','$message','$bouncecat','$jobid','$domain','$ip','$server')");
if(strpos($message,'ALERT'!==false)){
@mysql_query("INSERT INTO `alerts` (`type`,`time`,`message`,`level`,`value`,`page`) VALUES('error','$now','$message','5','$ip','apps/loganalyzer/incl/datatracker.php')");
}
if($type=='d'){
@mysql_query("UPDATE `$server` SET `delivered`=`delivered`+1 WHERE `time`='$now'");
}elseif(($type=='b')&&($bouncecat!='bad')){
@mysql_query("UPDATE `$server` SET `errored`=`errored`+1 WHERE `time`='$now'");
}elseif(($type=='b')&&($bouncecat=='bad')){
@mysql_query("UPDATE `$server` SET `bounced`=`bounced`+1 WHERE `time`='$now'");
}elseif($type=='c'){
@mysql_query("UPDATE `$server` SET `unsubscribed`=`unsubscribed`+1 WHERE `time`='$now'");
}