gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 10:06:10 25 4
gpt4 key购买 nike

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

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 分钟。在新服务器上,这需要一个小时,并且在此期间缺少最后几条打印语句。 (参见//缺失)

我听说过绑定(bind)错误然后脚本在绑定(bind)后停止,但在这种情况下,它会在 while 循环后继续。但我没有更改查询或绑定(bind),所以应该没问题。我不确定如何调试它或在线搜索什么。我尝试逐渐注释掉和取消注释,发现在 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();
?>

最佳答案

查看下循环:

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

当循环开始时,$i 为 0,因此您可以看到文本“five 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++;
}

关于PHP在mysqli执行后跳过while循环中的打印语句,但在循环后显示打印,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52425897/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com