php在mysqli执行之后跳过while循环中的print语句,但在循环之后显示print

fhity93d  于 2021-06-19  发布在  Mysql
关注(0)|答案(3)|浏览(330)

我有一个php脚本,出于某种原因,它在mysqli执行之后跳过了几个print语句,但是在循环之后才打印。有什么想法吗?我把脚本移到了另一台服务器上。db仍在阿肯色州的小石城。脚本服务器在阿肯色州的小石城,现在在宾夕法尼亚州。没事的。我看到了:

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

它一直在运行,几分钟后我就把它关掉了。
在旧服务器上运行脚本时,需要5分钟。在新服务器上,它需要一个小时,并且在一段时间内丢失了最后几条print语句(见/(缺失)
我听说bind是错误的,然后脚本在绑定之后停止,但在本例中,它在while循环之后继续。但我没有更改查询或绑定,所以应该可以。我不知道如何调试这个或什么在线搜索。我试着逐渐注解和取消注解,发现在while循环中执行stmt4之后,脚本会变得很慢。
是的 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();
?>
u59ebvdq

u59ebvdq1#

你想要的有效解决方案

pbpqsu0x

pbpqsu0x2#

请参见下面的循环:

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

当循环开始时,$i是0,所以你可以看到文本“5b”。。。
然后$i将是1,因为表达式$i++。所以,关于if语句的任何其他条件都是不正确的。

qlvxas9a

qlvxas9a3#


// 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++;
}

相关问题