I’ve just found a very strange problem in my project. I have a class with several methods and everything worked fine until i tried to add a row to DB using one of the methods. Then i saw that there are 2 rows were added to the DB and that’s was after each query. I’ve started to search a problem, but everything seems right to me. Then I’ve started to delete method by method. many times over i’ve detected, that class created 2 times per request. This is my code:
<?
Class UpdateStates {
public function __construct() {
$millitime = round(microtime(true) * 1000);
file_put_contents($_SERVER['DOCUMENT_ROOT'] . '/test.txt', $millitime . "\n", FILE_APPEND);
}
}
$States = new UpdateStates();
?>
So each time i refresh the browser 2 lines of time appears in the text.txt, e.g.
1350614391795
1350614391973
1350614634801
1350614634835
1350614640527
1350614640646
What’s wrong with my code? Some tech info: Linux Debian 6.0, PHP Version 5.3.15-1~dotdeb.0, Apache/2.2.16.
Thanks a lot for any help!
Use firebug to see if another request is generated from the page, could happen with a unexpected HTML code or wrong url on a image, etc.