我有一个脚本,可以进行2-3次数据库查询,2次插入和1次更新。
我遇到的问题是,当我通过转到像www.domain.com/handler.php?a=1&b=2&c=3
这样的Web服务器页面手动测试脚本时,我完全得到了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
这是一个失败但没有输入任何内容的数据库,当我手动执行时没有错误,它就像一个魅力,但使用套接字失败,只有在INSERT上,UPDATE通过套接字连接工作???
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'");
}
答案 0 :(得分:0)
虽然我不确切地知道问题是什么,但我有2条建议供您调试: