4

I have this weird problem, and I don't know how to get rid of it.

Example: I put a var_dump('test') in my code at the top of the page. Just to edit something. Alt-tab to chrome, cmd-R to refresh.

The var_dump('test')is not there. Cmd-R again. Still not there.

Then I wait for a minute, and refresh... And suddenly it's there.

Basically: I will always see code changes, but not immediately.

I have this problem in PhpStorm and Netbeans, so it's probably not an IDE problem.

Edit: I have also tried this in different browsers, and they all have this as well, so it's not a browser-related problem.

Has anyone had this problem before? Does anyone know a solution to this? It's really difficult to work efficiently if I have to wait to see my edited code live...

EDIT: I'm working on my localhost. Server setup is with MAMP.

REQUEST HEADERS:

Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Encoding:gzip,deflate,sdch
Accept-Language:nl-NL,nl;q=0.8,en-US;q=0.6,en;q=0.4
Cache-Control:no-cache
Connection:keep-alive
Cookie:projekktorplayertracking_prkusruuid=D1A39803-4DE3-4C0B-B199-6650CF0F8DE5; Akamai_AnalyticsMetrics_clientId=C355983152DF60151A0C6375798CD52E8F09B995; __atuvc=4%7C47%2C0%7C48%2C0%7C49%2C17%7C50%2C47%7C51; PHPSESSID=885c62f543097973d17820dca7b3a526; __utma=172339134.2012691863.1384502289.1387377512.1387442224.41; __utmb=172339134.1.10.1387442224; __utmc=172339134; __utmz=172339134.1384502289.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)
Host:local.sos
Pragma:no-cache
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36

RESPONSE HEADERS:

Connection:Keep-Alive
Content-Length:681
Content-Type:text/html
Date:Thu, 19 Dec 2013 09:00:54 GMT
Keep-Alive:timeout=5, max=99
Server:Apache/2.2.25 (Unix) mod_ssl/2.2.25 OpenSSL/0.9.8y DAV/2 PHP/5.5.3
X-Pad:avoid browser bug
X-Powered-By:PHP/5.5.3

EDIT: I was messing around in MAMP's settings. My PHP version was 5.5.3, but then I couldn't set any PHP Extensions.

When I put PHP version on 5.2.17 (my only other option), I was able to set Cache to XCache.

So... Now my page is always up-to-date when reloaded immediately.

Thanks to anyone that replied and helped me with this!

Bakkie009
  • 239
  • 2
  • 6
  • What when you try CTRL+F5 (or CMD+F5) – Maarkoize Dec 19 '13 at 08:52
  • 1
    Do you work locally ? What is the webserver used ? Which browser ? – OlivierH Dec 19 '13 at 08:52
  • How awckward O_o I suppose there is some sort of time-machine shenanigans in the background? Or it could be your server config? (but not likely) – hanzo2001 Dec 19 '13 at 08:53
  • @OlivierH it does state Chrome - of which, does it do this even with incognito mode? – MackieeE Dec 19 '13 at 08:53
  • @Marcel He's not talking about Windows here. – deceze Dec 19 '13 at 08:53
  • Oh ok. Then it could be CMD+SHIFT+R – Maarkoize Dec 19 '13 at 08:54
  • This is probably not a question suitable for Stackoverflow... It sounds like a server issue. Maybe caching? You need to include information about your setup. Do you work locally, which server do you use? – Frederik Wordenskjold Dec 19 '13 at 08:55
  • Please include full *request* and *response* headers as shown in Chrome debugging tools 'Network' tab. – Niels Keurentjes Dec 19 '13 at 08:57
  • Are you using some, framework or CMS engine ? If so some of the CMS engines tends to cache the displayed views. – Risto Novik Dec 19 '13 at 08:57
  • My money is on opcache or some other form of caching? – PeeHaa Dec 19 '13 at 08:58
  • Do you explicitly save your file after editing? Maybe you IDE doesn't save it directly, but after some time... – veelen Dec 19 '13 at 09:00
  • Please answer your question with your own answer and set it as thé answer so others can easily find question and answer related to their own problem. – Luceos Dec 19 '13 at 10:10
  • This was my first question on stackoverflow, so I didn't know that. Done now. – Bakkie009 Dec 19 '13 at 10:55
  • I'm having the same issue, developing locally with PHPStorm on Chrome on Mac OSX Mavericks. The solution of downgrading PHP won't work for me as I need PHP 5.5. So here is the actual best solution: http://stackoverflow.com/questions/19073270/stop-caching-for-php-5-5-3-in-mamp – Acyra Nov 07 '14 at 13:57

4 Answers4

1

There are three possible causes (I can think of):

  1. Your browser is caching the file, on development sites you can disable your cache (eg in Chrome press F12 and click on the gear in the bottom right, check the checkbox to disable cache while developer tools are open - keep it open in development areas)
  2. Your connection to your server is lagging, this can be caused by delayed uploads by your IDE or by your connection. You can test this by opening a SSH connection and check modified times after saving (eg; repeatedly pressing ls -la or watch -n 1 ls -la in the directory of the file)
  3. In case of some applications another form of caching might exist. This can be APC or Opcache. In order for this to be the possible cause it might be wise to exclude the above first. This step requires you to analyze the headers send by the server as available on the Network tab of the devtools (in case of chrome)
Luceos
  • 6,629
  • 1
  • 35
  • 65
  • I've tried with disabled cache in Chrome and hard refreshes (Chrome and Firefox). Doesn't work. So it's not browser-related... – Bakkie009 Dec 19 '13 at 09:14
1

This was the solution:

I was messing around in MAMP's settings. My PHP version was 5.5.3, but then I couldn't set any PHP Extensions.

When I put PHP version on 5.2.17 (my only other option), I was able to set Cache to XCache.

Then it worked.

But then I found this thread.

 In your MAMP Dir go to : /bin/php/php5.5.3/conf/php.ini
    And comment the Opcahe lines:



 [OPcache]
    ;zend_extension="/Applications/MAMP/bin/php/php5.5.3/lib/php/extensions/no-debug-non-zts-20121212/opcache.so"
    ;  opcache.memory_consumption=128
    ;  opcache.interned_strings_buffer=8
    ;  opcache.max_accelerated_files=4000
    ;  opcache.revalidate_freq=60
    ;  opcache.fast_shutdown=1
    ;  opcache.enable_cli=1

Now I'm programming in PHP 5.5.3, and my pages are immediately updated.

Community
  • 1
  • 1
Bakkie009
  • 239
  • 2
  • 6
0

Not sure about NetBeans, but PhpStorm updates the file as you type (there is no need to explicitly save). HOWEVER, the auto-save debounce is OS dependant. Mac might wait for file changes slower to refresh their contents. I'm not sure how to do it on OS X, because I can't recall the name of the feature but another workaround is to explicitly save the file using Command+S.

casraf
  • 21,085
  • 9
  • 56
  • 91
-1

I had a similar sounding problem working locally with .php and .less files in IE and Chrome. Something was causing the css file to be cached or cookied or something and wouldn't display the changes made to the .less file. We fixed it by creating a php variable of the time stamp and then attaching the variable to the end of the file name and source link. The browser treated it like a new file and would always load it.

I don't have the actual code to do that right now (I'm at home) but will look for it tomorrow at work.

Obviously, this isn't the same problem you're having, but I thought it might give you a new direction to research your issue.

jsilver951
  • 13
  • 3
  • That is relevant to linked files like LESS, CSS, images; that is the cache. PHP files aren't cached, they're being re-run every time the browser accesses them (unless AJAX specifically caches responses, in which case it's a bit different than asset caching) – casraf Dec 19 '13 at 09:04
  • I didn't say PHP files were cached. I said the CSS files were being cached, and fixed that by using PHP to change the file name of the Css file and link. – jsilver951 Dec 21 '13 at 23:46
  • Which still makes it irrelevant, because OP was talking about PHP files taking more than one refresh to change. – casraf Dec 22 '13 at 07:59