PHP在mysqli执行后在while循环中跳过打印语句,但在循环后显示print

时间:2018-09-20 13:08:35

标签: php mysql linux strace

我有一个php脚本,由于某种原因,它在mysqli执行后跳过了一些打印语句,但在循环后打印。有任何想法吗?我将脚本移至其他服务器。 DB(仍然)在阿肯色州的小石城中。脚本服务器位于阿肯色州的小石城,现在位于宾夕法尼亚州。可以。我看到了:

PING littlerock db (ip...) 56(84) bytes of data.
64 bytes from littlerock (ip...): icmp_seq=1 ttl=56 time=36.5 ms

它继续运行,几分钟后我按ctrl-c退出。

当我在旧服务器上运行脚本时,需要5分钟。在新服务器上,它需要一个小时,并且会在一段时间内丢失最后几个打印语句。 (请参见//缺少)

我听说绑定错误,然后脚本在绑定之后停止,但是在这种情况下,它在while循环之后继续。但是我没有更改查询或绑定,所以应该没问题。我不确定该如何调试或在线搜索什么。我尝试注释掉并逐渐取消注释,发现在stmt4在while循环中执行之后,脚本变得很慢。

我做了

  

php -i | grep max_execution_time

然后查看

max_execution_time => 0 => 0

我认为这意味着没有最大值,因此不应超时。

我做了一个strace php script.php,看到了这种东西:

write(9, "\17\0\0\0\27\1\0\0\0\0\1\0\0\0\0\0\2AR", 19) = 19
read(9, "\1\0\0\1\0017\0\0\2\3def\7netcool\7domains\7do"..., 16384) = 93
poll([{fd=6, events=POLLIN|POLLPRI}], 1, 0) = 0 (Timeout)
poll([{fd=6, events=POLLIN|POLLPRI}], 1, 0) = 0 (Timeout)
write(6, "\210\0\0\0\27\1\0\0\0\0\1\0\0\0\4\20\0\0\f10.66.46.141\17"..., 140) = 140
read(6, "\7\0\0\1\0\0\0\2\0\4\0", 16384) = 11
poll([{fd=8, events=POLLIN|POLLPRI}], 1, 0) = 0 (Timeout)
poll([{fd=8, events=POLLIN|POLLPRI}], 1, 0) = 0 (Timeout)
write(8, "\32\0\0\0\27\1\0\0\0\0\1\0\0\0\0\0\6Adtran\6TA5000", 30) = 30
read(8, "\1\0\0\1\3M\0\0\2\3def\7netcool\22vendor_mod"..., 16384) = 286
poll([{fd=9, events=POLLIN|POLLPRI}], 1, 0) = 0 (Timeout)
poll([{fd=9, events=POLLIN|POLLPRI}], 1, 0) = 0 (Timeout)
write(9, "\17\0\0\0\27\1\0\0\0\0\1\0\0\0\0\0\2AR", 19) = 19

,但随后却是ctrl-c / z。

<?php
print "zero \n";
error_reporting(E_ALL ); //& ~E_NOTICE | ~E_WARNING
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR ."logGen/loggen.class.php");
$err = new logGen('e', '/opt/na/NAC_Dslam/junk/logexample.log', TRUE);

$err->logThis("Running script");

// Date information
date_default_timezone_set('America/Chicago');//date_default_timezone_set
$last_week = strtotime("last week");
$last_week = Date('Y-m-d H:i:s', $last_week);
print "one \n";

// Oracle Connection details
$db = "(DESCRIPTION=(ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = <host>)(PORT = <port>)))(CONNECT_DATA=(SID=<db>)))";
$conn = oci_connect("<u>", "<p>", $db);

$query = "SELECT * FROM table1.view1 WHERE Vendor IN ('Ad','Cal') AND IP_ADDRESS NOT IN('RQ...', '0.0.0.0')"; 

$ora_stmt = oci_parse($conn, $query);
oci_execute($ora_stmt);
print "one b \n"; //i see this
//depo NAC Connection Details
$mysqli0 = new mysqli('<host>', '<u>', '<p>', "db1");

print "two \n"; //see this
// db connection details
$mysqli3 = new mysqli('<host>', '<db>', '<u>', '<p>');

// Only insert new records, any records that have just been modified should be updated instead. This is blocked via the
//  node's IP as it is a unique key in the Netcool sis_elements table.
$stmt6 = $mysqli0->prepare("INSERT INTO mytable1(node_ipv4, nodealias, fqdn, region, State, class, vendor, model, head_node_monitor_pt, domain, date_updated, date_created)
                            VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, NOW(), NOW())
                            ON DUPLICATE KEY UPDATE node_ipv4=?, nodealias=?, fqdn=?, region=?, State=?, class=?, vendor=?, model=?, head_node_monitor_pt=?, domain=?");
print "two b\n"; //see this
$stmt6->bind_param('ssssssssssssssssssss', $db_ipv4, $db_nodealias, $db_fqdn, $db_region, $db_state, $db_class, $db_vendor, $db_model, $db_head_node,$db_domain,
                               $db_ipv4, $db_nodealias, $db_fqdn, $db_region, $db_state, $db_class, $db_vendor, $db_model, $db_head_node, $db_domain);

// db connection details
$mysqli4 = new mysqli('<db>', '<table>', '<u>', '<p>');
print "three \n"; //see this
$stmt4 = $mysqli4->prepare("SELECT vendor, model, class
                            FROM vendor_model_class
                            WHERE source_system = 'DMV'
                            AND vendor = ?
                            AND model = ?"); 
print "three b\n"; //see this
$stmt4->bind_param("ss", $db_vendor, $db_model);
$stmt4->bind_result($set_vendor, $set_model, $set_class);
print "three c\n";
// dbconnection details
$mysqli5 = new mysqli('<host>', '<db>', '<u>', '<p>');

$stmt5 = $mysqli5->prepare("SELECT domain
                            FROM domains
                            WHERE state = ?"); 
print "four \n"; //see this
$stmt5->bind_param("s", $db_state);
$stmt5->bind_result($db_domain);
print "five \n"; //see this

$i = 0;
// Loop through the results
while($row = oci_fetch_array($ora_stmt, OCI_ASSOC+OCI_RETURN_NULLS)) {

  $db_state = trim($row['STATE']);
  $db_nodealias = trim($row['DSLAM']);
  $db_vendor = trim($row['VENDOR']);
  $db_model = trim($row['MODEL']);
  $db_region = trim($row['STATE']);
  $db_state = trim($row['STATE']);
  $db_nodealias = trim($row['DSLAM']);
  $db_ipv4 = trim($row['IP_ADDRESS']);
  $db_head_node = trim($row['HEAD_NODE_MONITOR_PT']);
  $db_monitor_cat = trim($row['MONITORING_CATEGORY']);

  $stmt4->execute(); //it's slow after this event if I comment the rest of while loop out
  if($i % 10 == 0)
     print "five b " . $i++. "\n"; //I see five b 0 and that's it
  while($stmt4->fetch()) {}

  $db_class = $set_class;

  $stmt5->execute();
  if($i % 10 == 0)
     print "six " . $i++. "\n"; //missing
  while($stmt5->fetch()) { }  

  $stmt6->execute();
if($i % 10 == 0)
     print "seven " . $i++. "\n";  //missing
}

print "eight \n"; //I see this
$mysqli4->close();
$mysqli5->close();
$mysqli0->close();
?>

1 个答案:

答案 0 :(得分:1)

请参见下循环:

while($row = oci_fetch_array($ora_stmt, OCI_ASSOC+OCI_RETURN_NULLS)) 

当循环开始时,$ i为0,因此您可以看到文本“ 5 b” ...

然后由于表达式$ i ++,$ i将为1。因此,关于if语句的任何其他条件都不正确。

--------------------您想要的有效解决方案----------------------- ---

// Loop through the results
while($row = oci_fetch_array($ora_stmt, OCI_ASSOC+OCI_RETURN_NULLS)) {

  $db_state = trim($row['STATE']);
  $db_nodealias = trim($row['DSLAM']);
  $db_vendor = trim($row['VENDOR']);
  $db_model = trim($row['MODEL']);
  $db_region = trim($row['STATE']);
  $db_state = trim($row['STATE']);
  $db_nodealias = trim($row['DSLAM']);
  $db_ipv4 = trim($row['IP_ADDRESS']);
  $db_head_node = trim($row['HEAD_NODE_MONITOR_PT']);
  $db_monitor_cat = trim($row['MONITORING_CATEGORY']);

    $stmt4->execute(); //it's slow after this event if I comment the rest of while loop out
      if($i % 10 == 0)
         print "five b " . $i. "\n"; 
      while($stmt4->fetch()) {}

      $db_class = $set_class;

      $stmt5->execute();
      if($i % 10 == 0)
         print "six " . $i. "\n"; 
      while($stmt5->fetch()) { }  

      $stmt6->execute();
    if($i % 10 == 0)
         print "seven " . $i. "\n"; 
    $i++;
}