(PHP) MySQL creates two rows instead of one in Chrome - php

I've already looked through other questions but couldn't find an answer to this specific problem since it seems its all about the Chrome browser.
I stripped down my code to debug this problem and the only thing I'm executing now is loading my database and doing an INSERT.
However it always inserts two rows instead of one row.
Then I tested this with Firefox and there are no problems. I also disabled all my Chrome Extensions and it's still unchanged. I can't figure out what else might be causing this. Like I said, it works in other browsers.

there is some discussion about chrome making multiple requests here
the gist seems to be that there are some things that could cause chrome to make an additional request, including (but not limited to):
link tags with an empty href property <link rel="shortcut" href="">
image, iframe, or scripts tags with an empty or '#' src property <img src="#">
chrome fetching the favicon
do any of those apply?
regardless of what is causing the double GET, a good solution would be to be to follow standard web development best practices: don't change application state as a result of a GET call. Require a POST.

Server side code (e.g. PHP script) does not depend of your browser. So it couldn't behave differently in different browsers.
But yes, in some cases you may have your code executed two times for single page hit.
Lets assume you have a code that inserts new row every time your page has been visited (for example: old-school visits counter). When using Google Chrome you may be surprised, cause you'll get two inserted rows per single page hit. That happens because Google Chrome makes second request to page just for getting favicon.
Other possibility is an weird condition in your code. Eg. if it is chrome, do something else/more

Related

Laravel 5.0 Blade including tag causes slow render time and kills the page

I'm getting a weird issue with including tag. It slows down the page and sometimes kills it. I noted the render time with including tag and without it. See it in the screen shot:
http://prntscr.com/ho1cms http://prntscr.com/ho1boe
It has been working fine for a year, but now suddenly killing pages.
http://prntscr.com/ho1ebb
Since this include tag is mentioning javascript, it is possible that the slow down occurs in javascript context. Could be an asset failing to load in sync or just some very poor code running in sync. That would explain the blank page during loading.
Have you tried to look at how things where going in a browser console or even better browser network audit tool ?
Another thing could be some problems in the included files themselves, but I don't think you will find a reason in the include process itself.

Double GET request in text file?

I have a file "host.php" which gives plain text. When I try to run it in browser, once per few refreshes one variable increases by 2, not 1. I tried placing session variable on end, to check if its script error (double var increment) or a http error. Looks like it increases the same way. Also checked Chrome Network debugger. Found one error (with browser trying to load favicon.ico), fixed it and the problem still occurs.
I have seen this question:
What can cause a double page request? which had the same problem, but it wasn't solution for me. I don't use ads or html elements - its plain text.
The result:
The page sometimes loads twice. There is no network errors, like empty src. And its plain text, not html.
The question:
How to fix it? How to prevent page loading twice?
PS: The page never uses POST requests, only get.
I'm not sure is it the correct answer, so I won;t yet mark it as correct.
When I tried the script in Chrome on other device (in Incognito mode), everything worked well (or I just didn't saw...). On my device I'm also using Chrome.
As Incognito mode uses different cookies probably even for each tab (?), it might be fault of some external cookies running (like in linked question, ads could import some). Chrome debugger now only shows 1 cookie, which is PHPSESSID from my site, it looks like its not that.
Afterall, I pressume that its user's device/browser/extensions fault. I also tried disabling Adblock, but that didn't solve the problem.

Site is calling same file multiple times but doesn't show in code?

I am honestly not sure where the issue lays but here is my problem:
I have a single file: card.gif. When I check firebug or Google pagespeed, I learn the file is called twice during the page fetch once as normal file name and a second time with a random number (that does not change). Example:
card.gif
card.gif?1316720450953
I have scoured my actual source code, the image is only called once. It is not called in a CSS file. To be honest I have no idea what is the issue, some thought that when I originally installed mod_pagespeed that it appended ID's to each image in cache for any future overwrites but I can't be certain.
Has anybody ever had this issue before?
In the end - Dagon's comments above led me to believe that things like Firebug and Pagespeed may not always be correct. I do show two images being loaded in the timelines for both plugins but it is very difficult for me to decifer otherwise. If another answer is provided contradicting this, I am more than happy to test that theory.

URL structure causing incomplete page to be returned by PHP's file_get_contents()

I've been doing some scraping with PHP and getting some strange results on a particular domain. For example, when I download this page:
http://pitchfork.com/reviews/tracks/
It works fine. However if I try to download this page:
http://pitchfork.com/reviews/tracks/1/
It returns an incomplete page, even though the content is exactly the same. All subsequent pages (tracks/2/, tracks/3/, etc) also return incomplete data.
It seems to be a problem with the way the URLs are formed during pagination. Most other sections on the site exhibit the same behaviour (the landing page works, but not subsequent pages). One exception is this section:
http://pitchfork.com/forkcast/
Where forkcast/2/ etc work fine. This may be due to it being only one directory deep, where most other sections are multiple directories deep.
I seem to have a grasp on WHAT is causing the problem, but not WHY or HOW it can be fixed.
Any ideas?
I have tried using file_get_contents() and cURL and both give the same result.
Interestingly, on all the pages that do not work, the incomplete page is roughly 16,000 chars long. Is this a clue?
I have created a test page where you can see the difference:
http://fingerfy.com/test.php?url=http://pitchfork.com/reviews/tracks/
http://fingerfy.com/test.php?url=http://pitchfork.com/reviews/tracks/1/
It prints the strlen() and content of the downloaded page (plus it makes relative urls into absolute, so that CSS is correct).
Any hints would be great!
UPDATE: Mowser, which optimizes pages for mobile has no trouble with these pages (http://mowser.com/web/pitchfork.com/reviews/tracks/2/) so the must be a way to do this without it failing....
It looks like pitchfork's running a CMS with "human" urls. That'd mean that /review/tracks would bring up a "homepage" with multiple postings listed, but "/reviews/tracks/1" would bring up only "review #1". It's possible they've configured the CMS to output only a fixed length excerpt, or have an output filter mis-configured and chop off the individual posts pages early.
I've tried fetching /tracks/1 through /tracks/6 using wget, and they all have different content which terminates at 16,097 bytes exactly, usually in the middle of a tag. So, it's not likely this is anything you can fix on your end, as it's the site itself sending bad data.

Sporadic/random page display problems

This is for a website written in PHP (with very minimal JS, only used for a drop-down menu), using CSS, and a mySQL DB.
95 percent of the time my pages display fine. But occasionally as I click back and forth between pages, the page I've just clicked to does not display properly. It's always the same pattern of non-display when it happens: the top 10 pixels of the header (which is a 220-pixel high jpg) will be displayed, then immediately below that the footer division of my page displays. The rest of the header image and header division are missing, as is the content division -- so I end up with a page that's about 60 pixels tall and is missing the entire middle portion of its content.
If you hit the refresh button, the "bad" page will immediately display properly.
This happens randomly, as far as I can tell; it might happen on any page in my site. Sometimes it doesn't happen for thirty or forty or more page views, and then it will pop up again. Sometimes it might happen two or three times in a row.
I've tried making sure all my img tags have height and width specified, tried using PHP's flush function after right before the tag, adding a flush right before the function that access the database. Nothing I can think of has helped.
This problem has also occurred (in a similar random and only very occasional fashion) for the three other people who are helping me test this site, so the issue is not my particular computer or browser (although it may be Firefox related, since that's the browser we all seem most likely to stumble on the problem with).
Any suggestions would be deeply appreciated. This is frustrating as all get out. I'm still pretty new at web programming, and I can't find anything that explains this strange problem.
Thanks!!!
Sounds like a server problem to me as everything else seems to be random. I would check for errors in the log files and if you have the opportunity, check the site on another server.
Without knowing anything else about your site, I'm going to go out on a limb and suggest you're embedding a block level element inside an inline element.
Maybe something like
<span id="header">
<div id="content">...</div>
</span>
I say this because
Googling for sporadic layout failures returns very little
I've just fixed an issue that sounds similar. I was accidentally embedding a few floating divs inside an anchor tag. Most of the time, Firefox would treat the anchor as a block level element. But occasionally, it wouldn't, and the divs inside the anchor would be spewed all over the page.

Categories