简体   繁体   English

PHP和MySQL运行两次,但仅回显一次

[英]PHP and MySQL Runs twice but only echos once

I'm troubleshooting a problem on my site and I have narrowed it down to the php being run twice. 我正在解决我网站上的问题,并且将其范围缩小到运行两次的php。 I assume this means the page is loaded twice but the catch is that the code is only echoed or printed once. 我认为这意味着页面被加载了两次,但要注意的是代码仅回显或打印了一次。 I figured this out using ChromePHP to log some text. 我使用ChromePHP记录了一些文本来解决这个问题。 That text prints in the console twice every now and again. 该文本一次又一次在控制台中打印两次。

The main issue is that I'm making a mysql query and setting a variable. 主要问题是我正在执行mysql查询并设置变量。 In an example. 在一个例子中。 It prints the ID number it gets as 2, but then the code randomly loads again and that variable is now set to something else... lets say 15 or whatever. 它打印得到的ID号为2,但是代码再次随机加载,并且该变量现在设置为其他值……可以说15或其他值。 But visually the echoed variable is still 2. 但是在视觉上,回显的变量仍为2。

include 'php/classes/ChromePhp.php';
$link = mysqli_connect($host, $dbuser, $dbpass, $dbname );

if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}

if ($result = mysqli_query($link,'SELECT questionID FROM questions order by rand() limit 1')) {
    $row = mysqli_fetch_array($result);
    printf("Question ", $row['questionID']);
    mysqli_free_result($result);
    ChromePhp::log('QUESTIONID '.$row['questionID']);
}       
if($link) 
    mysqli_close($link);
?>

I've looked around and people say it could be the favicon being loaded separately or the .htaccess redirect which I use. 我环顾四周,人们说这可能是单独加载的图标或我使用的.htaccess重定向。 I took the .htaccess off and I still have this issue. 我取消了.htaccess,但仍然遇到此问题。

Any pointers to a direction would be nice. 任何指向方向的指针都很好。

Thanks 谢谢

I discovered it was a Google Chrome Extension: FirePHP that was causing the reload of code. 我发现这是一个Google Chrome扩展程序:FirePHP,导致代码重新加载。 Once I deleted the extension everything started working again! 删除扩展程序后,一切都将重新开始!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM