• 系统:Ubuntu 16.04.6 LTS
  • 服务器:Apache/2.4.18
  • 开发框架:Thinkphp 5.0
  • apache配置:





网上都是说输入:FileETag INode Mtime Size就开启了,确实Header有ETag,但是不起作用,麻烦各位大佬们解答,谢谢!!!!


1. 第一次请求:Crtl + F5


2. 第二次请求:F5(在max-age期间内)


3. 第三次请求:F5(在max-age期间外)



Csdn user default icon

response 中包含如下信息: Accept-Ranges bytes Cache-Control max-age=2592000 Connection Keep-Alive Content-Length 4929 Content-Type image/jpeg Date Fri, 03 May 2013 07:04:22 GMT Etag "a98107b-1341-4d49550d20780" Expires Sun, 02 Jun 2013 07:04:22 GMT Keep-Alive timeout=15, max=95 Last-Modified Thu, 31 Jan 2013 13:07:58 GMT Server Apache 当我再次请求时, 服务器返回的200和而不是期望的304 已经在.htaccess中已经配置: ExpiresActive On ExpiresByType image/gif "access plus 30 days" 具体是什么原因引起的呢? 帮助分析一下.


<div class="post-text" itemprop="text"> <p>I'm working currently on REST API. I wanted to check if HTTP cache is working fine, but unfortunatelly I doesn't work at all. No matter what I do, it always return HTTP code 200 while it should return 304 from what I know.</p> <p>Here is my PHP code:</p> <pre><code>public function getList() { $this-&gt;addHeaders(array( 'Cache-Control' =&gt; 'public, must-revalidate, max-age=120', 'eTag' =&gt; 'xyz123', )); $array = array( 'foo' =&gt; 'bar', 'nested' =&gt; array( 'lorem' =&gt; 'ipsum', 'dolor' =&gt; 'sit amet' ) ); $this-&gt;addHeader('Content-Length', strlen(json_encode($array, true))); return new JsonModel($array); } </code></pre> <p><strong>Response/Request</strong></p> <p><a href="https://i.stack.imgur.com/gM2jJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gM2jJ.png" alt="enter image description here"></a></p> <p>ETag doesn't change, so requests except first one should be served from cache. Am I wrong?</p> <p>I was following these 2 articles:</p> <ul> <li><a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Caching" rel="nofollow noreferrer">https://developer.mozilla.org/en-US/docs/Web/HTTP/Caching</a></li> <li><a href="https://developers.google.com/web/fundamentals/performance/optimizing-content-efficiency/http-caching?hl=en" rel="nofollow noreferrer">https://developers.google.com/web/fundamentals/performance/optimizing-content-efficiency/http-caching?hl=en</a></li> </ul> <p>I also checked with <strong>weak validator</strong>- Last-Modified but I got same problem. Browser sends correct header in <strong>Request</strong>, but I still get 200 in response</p> </div>


<div class="post-text" itemprop="text"> <p>The browser caching is not working as my Apache mod_expires is enabled. I have checked this through phpinfo() under Loaded Modules</p> <p>Below is my code in htaccess</p> <pre><code>&lt;IfModule mod_expires.c&gt; ExpiresActive On ExpiresDefault "access plus 1 seconds" ExpiresByType image/x-icon "access plus 2592000 seconds" ExpiresByType image/jpeg "access plus 2592000 seconds" ExpiresByType image/png "access plus 2592000 seconds" ExpiresByType image/gif "access plus 2592000 seconds" ExpiresByType application/x-shockwave-flash "access plus 2592000 seconds" ExpiresByType text/css "access plus 604800 seconds" ExpiresByType text/javascript "access plus 216000 seconds" ExpiresByType application/x-javascript "access plus 216000 seconds" ExpiresByType text/html "access plus 600 seconds" ExpiresByType application/xhtml+xml "access plus 600 seconds" &lt;/IfModule&gt; &lt;IfModule mod_headers.c&gt; &lt;FilesMatch "\\.(ico|jpe?g|png|gif|swf)$"&gt; Header set Cache-Control "max-age=2692000, public" &lt;/FilesMatch&gt; &lt;FilesMatch "\\.(css)$"&gt; Header set Cache-Control "max-age=2692000, public" &lt;/FilesMatch&gt; &lt;FilesMatch "\\.(js)$"&gt; Header set Cache-Control "max-age=2692000, private" &lt;/FilesMatch&gt; &lt;FilesMatch "\\.(x?html?|php)$"&gt; Header set Cache-Control "max-age=600, private, must-revalidate" &lt;/FilesMatch&gt; Header unset ETag Header unset Last-Modified &lt;/IfModule&gt; &lt;IfModule mod_headers.c&gt; &lt;FilesMatch "\.(bmp|css|flv|gif|ico|jpg|jpeg|JPG|js|pdf|png|svg|swf|tif|tiff)$"&gt; Header set Last-Modified "Mon, 27 Aug 2012 00:00:00 GMT" &lt;/FilesMatch&gt; &lt;/IfModule&gt; </code></pre> </div>


<div class="post-text" itemprop="text"> <p>I am trying to speed up some ajax calls by facilitating ETags. What I've got at the moment works sometimes (ajax calls that are 304 not modified take 40ms instead of 100ms). </p> <p>However, what I am noticing is, that chrome apparently only sends the If-None-Match header just for one request but <em>doees never</em> send it on Windows machines. This is quite a pity, as the resource this is about I am loading quite frequently to check for changes. Having ETags work all the time would be really helpful in that case. </p> <p>Here's what is happening on the wire: </p> <pre><code>GET /api/book/all/READ HTTP/1.1 Host: something Connection: keep-alive Pragma: no-cache Cache-Control: no-cache User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.110 Safari/537.36 Accept: */* Referer: http://something/ Accept-Encoding: gzip, deflate, sdch Accept-Language: de,en-US;q=0.8,en;q=0.6 Cookie: PHPSESSID=something </code></pre> <p>and the response: </p> <pre><code>HTTP/1.1 200 OK Date: Mon, 04 Apr 2016 06:00:17 GMT Server: Apache Expires: Thu, 19 Nov 1981 08:52:00 GMT ETag: "1" Cache-Control: "max-age=0, must-revalidate" Vary: Accept-Encoding Content-Encoding: gzip Keep-Alive: timeout=2, max=995 Connection: Keep-Alive Transfer-Encoding: chunked Content-Type: application/json;charset=utf8 </code></pre> <p>(as a side note, the ETag value I use refers to the version of the data - each time the data is modified, the version is incremented) </p> <p>In the next request, on Mac, Chrome will send the appropriate <code>If-None-Match</code> header, and the API will respond with a 304 not modified. However, the second time that resource is being loaded, there will not be any <code>If-None-Match</code> header again. </p> <p>On Windows, Chrome will just not send the <code>If-None-Match</code> header and therefore the server will respond with the full payload. </p> <p>The way I would like to have it, is that the browser would <em>always</em> send the <code>If-None-Match</code> header, so that the backend can do a proper job to decide if the cached API response is still fresh. </p> <hr> <p>on mac, this is how the second request (where the <code>If-None-Match</code> header is sent) looks: </p> <pre><code>GET /api/book/all/READ HTTP/1.1 Host: something Connection: keep-alive User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.110 Safari/537.36 Accept: */* Referer: http://something/ Accept-Encoding: gzip, deflate, sdch Accept-Language: de,en-US;q=0.8,en;q=0.6 Cookie: PHPSESSID=something If-None-Match: "1" </code></pre> <p>and the response: </p> <pre><code>HTTP/1.1 304 Not Modified Date: Mon, 04 Apr 2016 05:27:19 GMT Server: Apache Connection: Keep-Alive Keep-Alive: timeout=2, max=1000 Expires: Thu, 19 Nov 1981 08:52:00 GMT Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 Vary: Accept-Encoding </code></pre> </div>


<div class="post-text" itemprop="text"> <p>My Browser isn't sending back an If-Modified-Since Header for PHP generated Content</p> <p>on the first request my script sends:</p> <pre><code>(Status-Line) HTTP/1.1 200 OK Date Thu, 21 Jan 2010 08:55:25 GMT Server Apache/2.2.11 (Win32) PHP/5.2.9-1 X-Powered-By PHP/5.2.9-1 Pragma no-cache x-ua-compatible IE=8;FF=3;OtherUA=4 Last-Modfied Sat, 02 Jan 2010 02:02:20 GMT Content-Length 28453 Etag b98e0795b509be20146f58e06fbb624f Keep-Alive timeout=5, max=90 Connection Keep-Alive Content-Type image/png </code></pre> <p>it on the second request it sends:</p> <pre><code>(Request-Line) GET /kincumberunitingchurch/banner_image.php?id=1 HTTP/1.1 Host localhost User-Agent Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv: Gecko/2009122116 Firefox/3.0.17 Accept image/png,image/*;q=0.8,*/*;q=0.5 Accept-Language en-us,en;q=0.5 Accept-Encoding gzip,deflate Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive 300 Connection keep-alive Referer http://localhost/kincumberunitingchurch/index.php?sid=tgl9jq3f71nau3cj9vps6pna03 Cookie sid=tgl9jq3f71nau3cj9vps6pna03; PHPSESSID=m0jvven6d7l65pl6odm9ecfnt4 If-None-Match b98e0795b509be20146f58e06fbb624f Cache-Control max-age=0 </code></pre> <p>for other files the sever sends first:</p> <pre><code>(Status-Line) HTTP/1.1 200 OK Date Thu, 21 Jan 2010 08:55:25 GMT Server Apache/2.2.11 (Win32) PHP/5.2.9-1 Last-Modified Wed, 30 Dec 2009 02:40:58 GMT Etag "1000000013d35-40d9-47be9117f6280" Accept-Ranges bytes Content-Length 16601 Keep-Alive timeout=5, max=84 Connection Keep-Alive Content-Type image/png </code></pre> <p>and my browser send the following on the next request: </p> <pre><code>(Request-Line) GET /kincumberunitingchurch/img/cbuttons.png HTTP/1.1 Host localhost User-Agent Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv: Gecko/2009122116 Firefox/3.0.17 Accept image/png,image/*;q=0.8,*/*;q=0.5 Accept-Language en-us,en;q=0.5 Accept-Encoding gzip,deflate Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive 300 Connection keep-alive Referer http://localhost/kincumberunitingchurch/mystyle.css Cookie sid=tgl9jq3f71nau3cj9vps6pna03; PHPSESSID=m0jvven6d7l65pl6odm9ecfnt4 If-Modified-Since Wed, 30 Dec 2009 02:40:58 GMT If-None-Match "1000000013d35-40d9-47be9117f6280" Cache-Control max-age=0 </code></pre> <p>why would it send the If-Modified-Since header</p> </div>


<div class="post-text" itemprop="text"> <p>Happy Sunday,</p> <p>I am struggling and hair pulling for 3 days (fearing being almost bold by the end of the month) about the cache management on a Bitnami lamp-packaged instance running on Azure on Ubuntu 16.x.</p> <p>I am engaged in a PHP5 to PHP7 migration of a big system since several weeks, about to complete the task.</p> <p>My test site using the system can be reached here: <a href="https://stephanedeluca.com" rel="nofollow noreferrer">https://stephanedeluca.com</a> for you to look at the cache.</p> <p>Unfortunately, what I see, is that my PHP scripts are not immediately reflecting the changes I make once deployed (simple upload) to the server. And as a consequences, the UX is sometime destroyed by the fact the user often needs to double refresh, and in the worst cases, have to reload everything via the browser.</p> <p>On the previous system, everything was good, but on this new box, I've got the issue. The box uses php-fpm.</p> <p>What I achieved so far regarding the resolution of the cache management: </p> <ul> <li><p>from php.ini, I disabled the OPCache; — from the <code>.htaccess</code>, I have used mod_expires (I also installed mod_headers and mod_expires) as follows:</p> <pre> &lt;ifModule mod_expires.c&gt; ExpiresActive On ExpiresDefault "access plus 0 seconds" &lt;/ifModule&gt; &lt;FilesMatch "\.(flv|ico|pdf|avi|mov|ppt|doc|mp3|wmv|wav)$"&gt; &lt;ifModule mod_expires.c&gt; ExpiresDefault "access plus 1 years" &lt;/ifModule&gt; &lt;ifModule mod_headers.c&gt; #Header append Cache-Control "public" &lt;/ifModule&gt; &lt;/FilesMatch&gt; &lt;FilesMatch "\.(gif|jpg|jpeg|png)$"&gt; &lt;ifModule mod_expires.c&gt; ExpiresDefault "access plus 1 weeks" &lt;/ifModule&gt; &lt;ifModule mod_headers.c&gt; #Header append Cache-Control "public" &lt;/ifModule&gt; &lt;/FilesMatch&gt; &lt;FilesMatch "\.(xml|json|txt|html|js|css)$"&gt; &lt;ifModule mod_expires.c&gt; ExpiresDefault "access plus 2 hours" &lt;/ifModule&gt; &lt;ifModule mod_headers.c&gt; #Header append Cache-Control "proxy-revalidate" &lt;/ifModule&gt; &lt;/FilesMatch&gt; &lt;filesMatch "\.(php)$"&gt; FileETag None &lt;ifModule mod_headers.c&gt; Header unset ETag #Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate" Header set Pragma "no-cache" #Header set Expires "Tue, 15 Mar 1966 10:00:00 GMT+1" &lt;/ifModule&gt; &lt;/filesMatch&gt; </pre></li> <li><p>all my PHP scripts (via prepend) generate the following headers (right after session_start() is invoked):</p> <pre><code>// === No caching === session_cache_limiter('private'); session_cache_expire(0); // === Start session (must be after session_cache_X()) session_start(); header('Cache-Control: private, max-age=0, s-max-age=0, no-cache, no-store, must-revalidate', true); header("Last-Modified: $headerNow", true); </code></pre></li> </ul> <p>While looking at the browser request and response, I see that everything looks good imho:</p> <p>Request (as reported by Chrome)</p> <pre><code>Request URL: https://stephanedeluca.com/ Request Method: GET Status Code: 200 OK (from ServiceWorker) Referrer Policy: no-referrer-when-downgrade </code></pre> <p>Response:</p> <pre><code>Cache-Control: private, max-age=0, s-max-age=0, no-cache, no-store, must-revalidate Connection: Keep-Alive Content-Encoding: gzip Content-Type: text/html; charset=UTF-8 Date: Sun, 28 Apr 2019 12:36:57 GMT Expires: Thu, 19 Nov 1981 08:52:00 GMT Keep-Alive: timeout=5, max=100 Last-Modified: Sun, 28 Apr 2019 12:36:57 GMT Pragma: no-cache Server: Apache Transfer-Encoding: chunked Vary: Accept-Encoding X-Frame-Options: SAMEORIGIN X-Generated-On: Sun, 28 Apr 2019 12:36:57 GMT X-Powered-By: ZID/Webengine v24.0b27 -- Copyright (c) 1995-2019 MagicApps (http://MgcApps.com) -- All Rights Reserved Provisional headers are shown Referer: https://stephanedeluca.com/map.php Upgrade-Insecure-Requests: 1 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36 </code></pre> <p>I've also checked the cache by using <a href="https://www.giftofspeed.com/cache-checker/" rel="nofollow noreferrer">https://www.giftofspeed.com/cache-checker/</a> and the report is as expected.</p> <p>I am running out of ideas.</p> </div>


<div class="post-text" itemprop="text"> <p>I'm having a problem using this rewrite:</p> <pre><code>RewriteCond %{HTTP_HOST} www.example.com$ RewriteRule ^(.*)$ http://example.com$1 [R=301,L] </code></pre> <p>to remove the www url</p> <p>But the return is a url without a trailing slash. For example: example.com/subfolder which supposedly has a url of <strong>example.com/subfolder,</strong> but the result is <strong>example.comsubfolder</strong> whch breaks the url. Anyone could help me solving this? Many thanks!</p> <p>EDIT: here's my whole .htaccess</p> <pre><code>Header unset Pragma FileETag None Header unset ETag # 1 YEAR &lt;FilesMatch "\.(ico|pdf|flv)$"&gt; Header set Cache-Control "max-age=29030400, public" &lt;/FilesMatch&gt; # 1 WEEK &lt;FilesMatch "\.(jpg|jpeg|png|gif|swf)$"&gt; Header set Cache-Control "max-age=604800, public" &lt;/FilesMatch&gt; # 2 DAYS 172800 &lt;FilesMatch "\.(xml|txt|css|js)$"&gt; Header set Cache-Control "max-age=604800, proxy-revalidate" &lt;/FilesMatch&gt; # 1 MIN &lt;FilesMatch "\.(html|htm)$"&gt; Header set Cache-Control "max-age=60, private, proxy-revalidate" &lt;/FilesMatch&gt; &lt;FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$"&gt; Header set Expires "Thu, 15 Dec 2011 20:00:00 GMT" &lt;/FilesMatch&gt; RewriteEngine On RewriteCond %{QUERY_STRING} (^|\?)f=([0-9]+)&amp;t=([0-9]+)($|&amp;) RewriteRule ^viewtopic\.php$ /index.php?threads/%3/ [R=301,L] RewriteCond %{QUERY_STRING} (^|\?)f=([0-9]+)($|&amp;) RewriteRule ^viewforum\.php$ /index.php?forums/%2/ [R=301,L] RewriteCond %{HTTP_HOST} www.example.com$ RewriteRule ^(.*)$ http://example.com/$1 [R=301,L] # Use PHP5.4 Single php.ini as default AddHandler application/x-httpd-php54s .php # # Uncomment the statement below if you want to make use of # HTTP authentication and it does not already work. # This could be required if you are for example using PHP via Apache CGI. # ## EXPIRES CACHING ## &lt;IfModule mod_expires.c&gt; # Enable expirations ExpiresActive On # Default directive ExpiresDefault "access plus 1 month" # My favicon ExpiresByType image/x-icon "access plus 1 year†# Images ExpiresByType image/gif "access plus 1 month" ExpiresByType image/png "access plus 1 month" ExpiresByType image/jpg "access plus 1 month" ExpiresByType image/jpeg "access plus 1 month" # CSS ExpiresByType text/css "access 1 month†# Javascript ExpiresByType application/javascript "access plus 1 year" &lt;/IfModule&gt; ## EXPIRES CACHING ## #&lt;IfModule mod_rewrite.c&gt; #RewriteEngine on #RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L] #&lt;/IfModule&gt; &lt;Files "config.php"&gt; Order Allow,Deny Deny from All &lt;/Files&gt; &lt;Files "common.php"&gt; Order Allow,Deny Deny from All &lt;/Files&gt; DirectoryIndex portal.php index.php index.html index.htm RewriteCond %{HTTP_REFERER} !^http://example.com/.*$ [NC] RewriteCond %{HTTP_REFERER} !^http://example.com$ [NC] RewriteCond %{HTTP_REFERER} !^http://www.example.com/.*$ [NC] RewriteCond %{HTTP_REFERER} !^http://www.example.com$ [NC] RewriteRule .*\.(jpg|jpeg|gif|png|bmp)$ - [F,NC] # Start CloudFlare:example.com rewrite. Do not Edit RewriteCond %{HTTP_HOST} ^example.com RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L] # End CloudFlare rewrite. # Mod_security can interfere with uploading of content such as attachments. If you # cannot attach files, remove the "#" from the lines below. #&lt;IfModule mod_security.c&gt; # SecFilterEngine Off # SecFilterScanPOST Off #&lt;/IfModule&gt; ErrorDocument 401 default ErrorDocument 403 default ErrorDocument 404 default ErrorDocument 405 default ErrorDocument 406 default ErrorDocument 500 default ErrorDocument 501 default ErrorDocument 503 default &lt;IfModule mod_rewrite.c&gt; # If you are having problems with the rewrite rules, remove the "#" from the # line that begins "RewriteBase" below. You will also have to change the path # This line may be needed to enable WebDAV editing with PHP as a CGI. #RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] RewriteCond %{REQUEST_FILENAME} -f [OR] RewriteCond %{REQUEST_FILENAME} -l [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^.*$ - [NC,L] RewriteRule ^(data/|js/|styles/|install/|favicon\.ico|crossdomain\.xml|robots\.txt) - [NC,L] RewriteRule ^.*$ index.php [NC,L] &lt;/IfModule&gt; </code></pre> </div>


<div class="post-text" itemprop="text"> <p>Why will my jQuery ajax not support the <a href="http://en.wikipedia.org/wiki/HTTP_ETag" rel="nofollow">ETag</a> feature?</p> <p>You see in the second example, there is no "If-None-Match" header. But why?</p> <p>In both tested browser i have a 50% change to have a cache will pressing F5 but in simply reopen the page by clicking links it wont work.</p> <p><strong>Working none jQuery example</strong></p> <pre><code>var xmlhttp; if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 &amp;&amp; xmlhttp.status==200) { console.log( xmlhttp.responseText ); } } xmlhttp.open("GET","/energyManagerSensor/getCleanData/sensor_id/4?shrink_type=day&amp;from=18.11.2011&amp;to=23.02.2013",true); xmlhttp.send(); </code></pre> <p>REQUEST Header</p> <pre><code>Accept text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Encoding gzip, deflate Accept-Language de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7,de-CH;q=0.6,fr-FR;q=0.5,fr;q=0.4,en-gb;q=0.3,sr-RS;q=0.2,sr;q=0.1 Cache-Control max-age=0 Connection keep-alive Cookie PHPSESSID=iie173rsc5bqggll6uhmg6m7i6 Host sfportal3_hh_dev If-Modified-Since Tue, 12 Feb 2013 0:0:0 GMT If-None-Match 4SdayF1321570800T1361574000 Referer http://sfportal3_hh_dev/energyManagerDisplay/view/display_id/1 User-Agent Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:18.0) Gecko/20100101 Firefox/18.0 FirePHP/0.7.1 x-insight activate </code></pre> <p>RESPONSE Header</p> <pre><code>Cache-Control max-age=3600 Connection close Date Tue, 12 Feb 2013 06:16:23 GMT Expires Thu, 19 Nov 1981 08:52:00 GMT Server Apache/2.2.22 (Ubuntu) </code></pre> <p><strong>NOT Working jQuery example</strong></p> <pre><code>$.ajax({ url: "/energyManagerSensor/getCleanData/sensor_id/4?shrink_type=day&amp;from=18.11.2011&amp;to=23.02.2013", type: 'GET', dataType: "json", cache: true, ifModified: true, success: function(return_data) { console.log(return_data); } }); </code></pre> <p>REQUEST Header</p> <pre><code>Accept application/json, text/javascript, */*; q=0.01 Accept-Encoding gzip, deflate Accept-Language de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7,de-CH;q=0.6,fr-FR;q=0.5,fr;q=0.4,en-gb;q=0.3,sr-RS;q=0.2,sr;q=0.1 Connection keep-alive Cookie PHPSESSID=iie173rsc5bqggll6uhmg6m7i6 Host sfportal3_hh_dev Referer http://sfportal3_hh_dev/energyManagerDisplay/view/display_id/1 User-Agent Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:18.0) Gecko/20100101 Firefox/18.0 FirePHP/0.7.1 X-Requested-With XMLHttpRequest x-insight activate </code></pre> <p>RESPONSE Header</p> <pre><code>Cache-Control max-age=3600 Connection Keep-Alive Content-Type text/json Date Tue, 12 Feb 2013 06:18:41 GMT Etag 5SdayF1321570800T1361574000 Expires Tue, 12 Feb 2013 07:02:18 GMT Keep-Alive timeout=5, max=74 Last-Modified Tue, 12 Feb 2013 0:0:0 GMT Server Apache/2.2.22 (Ubuntu) Transfer-Encoding chunked X-Powered-By PHP/5.3.10-1ubuntu3 </code></pre> <p><strong>Test enviroment</strong></p> <ul> <li>Firefox 18.0.2 </li> <li>Chromium 24.0</li> </ul> </div>

“脏”.htaccess文件? [关闭]

<div class="post-text" itemprop="text"> <p>Heads up - I am a rather inexperienced techy, but certainly more technical than my companions! We have a WordPress site, and have installed/removed various plugins.</p> <p>The reason for this post is that we're suffering significant wait/TTFB issues on our website. The site is hosted on an Apache VPS, and I read that the .htaccess file can be problematic for such setups.</p> <p>Any advice/guidance will be greatly appreciated! We wanted to really just check that our .htaccess file looks "Ok"? To the untrained eye it looks like there is some repetition towards the bottom, and there is also the statement "AddType x-httpd-php54 .php" - which I wanted to make sure was necessary at this level. The .htaccess file is stored in the public_html folder.</p> <pre><code># BEGIN WpFastestCache &lt;IfModule mod_rewrite.c&gt; RewriteEngine On RewriteBase / RewriteCond %{HTTP_HOST} ^www.example.com [NC] RewriteRule ^(.*)$ http\:\/\/example\.com\/$1 [R=301,L] RewriteCond %{REQUEST_METHOD} !POST RewriteCond %{HTTPS} !=on RewriteCond %{REQUEST_URI} !(\/){2}$ RewriteCond %{QUERY_STRING} !.+ RewriteCond %{HTTP:Cookie} !^.*(comment_author_|wordpress_logged_in|wp_woocommerce_session).*$ RewriteCond %{HTTP:X-Wap-Profile} !^[a-z0-9\"]+ [NC] RewriteCond %{HTTP:Profile} !^[a-z0-9\"]+ [NC] RewriteCond %{HTTP_USER_AGENT} !^.*(iphone|midp|sony|symbos|nokia|samsung|mobile|epoc|ericsson|panasonic|philips|sanyo|sharp|sie-|portalmmm|blazer|avantgo|danger|palm|series60|palmsource|pocketpc|android|blackberry|playbook|ipad|ipod|iemobile|palmos|webos|googlebot-mobile|bb10|xoom|p160u|nexus|touch|SCH-I800|opera\smini|SM-G900R4|LG-|HTC|GT-I9505|WAP-Browser|Nokia309|Casper_VIA).*$ [NC] RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/all/$1/index.html -f [or] RewriteCond /var/sites/b/example.com/public_html/wp-content/cache/all/$1/index.html -f RewriteRule ^(.*) "/wp-content/cache/all/$1/index.html" [L] &lt;/IfModule&gt; &lt;FilesMatch "\.(html|htm)$"&gt; AddDefaultCharset UTF-8 &lt;ifModule mod_headers.c&gt; FileETag None Header unset ETag Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate" Header set Pragma "no-cache" Header set Expires "Mon, 29 Oct 1923 20:30:00 GMT" &lt;/ifModule&gt; &lt;/FilesMatch&gt; # END WpFastestCache # BEGIN GzipWpFastestCache &lt;IfModule mod_deflate.c&gt; AddType x-font/woff .woff AddOutputFilterByType DEFLATE image/svg+xml AddOutputFilterByType DEFLATE text/plain AddOutputFilterByType DEFLATE text/html AddOutputFilterByType DEFLATE text/xml AddOutputFilterByType DEFLATE text/css AddOutputFilterByType DEFLATE text/javascript AddOutputFilterByType DEFLATE application/xml AddOutputFilterByType DEFLATE application/xhtml+xml AddOutputFilterByType DEFLATE application/rss+xml AddOutputFilterByType DEFLATE application/javascript AddOutputFilterByType DEFLATE application/x-javascript AddOutputFilterByType DEFLATE application/x-font-ttf AddOutputFilterByType DEFLATE application/vnd.ms-fontobject AddOutputFilterByType DEFLATE font/opentype font/ttf font/eot font/otf &lt;/IfModule&gt; # END GzipWpFastestCache # BEGIN LBCWpFastestCache &lt;FilesMatch "\.(?i:ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf|x-html|css|xml|js|woff|woff2|ttf|svg|eot)(\.gz)?$"&gt; &lt;IfModule mod_expires.c&gt; ExpiresActive On ExpiresDefault A0 ExpiresByType image/gif A2592000 ExpiresByType image/png A2592000 ExpiresByType image/jpg A2592000 ExpiresByType image/jpeg A2592000 ExpiresByType image/ico A2592000 ExpiresByType image/svg+xml A2592000 ExpiresByType text/css A2592000 ExpiresByType text/javascript A2592000 ExpiresByType application/javascript A2592000 &lt;/IfModule&gt; &lt;IfModule mod_headers.c&gt; Header set Expires "max-age=2592000, public" Header unset ETag Header set Connection keep-alive FileETag None &lt;/IfModule&gt; &lt;/FilesMatch&gt; # END LBCWpFastestCache # BEGIN WordPress &lt;IfModule mod_rewrite.c&gt; RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] &lt;/IfModule&gt; # END WordPress # BEGIN WordPress &lt;IfModule mod_rewrite.c&gt; RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] &lt;/IfModule&gt; # END WordPress #Gzip AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript text/javascript #End Gzip AddType x-httpd-php54 .php </code></pre> </div>


<div class="post-text" itemprop="text"> <p>All,</p> <p>I have a PHP MVC application with the following structure:</p> <pre><code>helloworld - application - configs - controllers - models - layouts - include - library - public - .htaccess - index.php - design - css - style.css - struct.css - js - images - bg.gif </code></pre> <p>I have configured a virtual host in apache called <code>hello</code> that points to <code>helloworld/public/</code> folder. So, when I view my site, using <code>http://hello</code> all the CSS and images render fine.</p> <p>I deployed my site to a different server with similar config as above. When I access the website using <code>http://test.com/hello</code> the CSS and the background images contained in it, renders absolutely fine in Chrome and Safari, but background images fail on IE,Firefox and Opera. When the page refreshes on these browsers, it works just fine. I am unable to understand the behavior for this.</p> <p>The URLs in my CSS are written like this:</p> <pre><code>background-image: url(/design/images/bg.gif); </code></pre> <p>and my htaccess is like this:</p> <pre><code>Options -MultiViews -Indexes ##################################################### # CONFIGURE media caching # Header unset ETag FileETag None Header unset Last-Modified Header set Expires "Fri, 21 Dec 2012 00:00:00 GMT" Header set Cache-Control "max-age=7200, must-revalidate" SetOutputFilter DEFLATE # ##################################################### RewriteEngine On RewriteCond %{REQUEST_FILENAME} -s [OR] RewriteCond %{REQUEST_FILENAME} -l [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^.*$ - [NC,L] RewriteRule ^.*$ index.php [NC,L] </code></pre> <p>Can somebody explain why Background images and CSS is not rendering properly on page load, but renders after a page refresh?</p> </div>

PHP curl显示URL的输出,如'HTTP / 1.1 200 OK'

<div class="post-text" itemprop="text"> <p>I am trying to get the response/status code including the header for multiple URL's. My first try I was successful in getting the status code i.e. 200 or 301 or 302. But I want the output to be like <code>HTTP/1.1 200 OK</code> or <code>HTTP/1.1 302 Found</code> etc. </p> <p>Below is my code in which I get just the response code i.e. <code>200</code> or <code>301.</code></p> <pre><code>&lt;?php $line = "https://www.pnc.com"; $ch = curl_init($line); curl_setopt($ch, CURLOPT_URL, $line); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_HEADER,true); curl_setopt($ch, CURLOPT_NOBODY, true); curl_setopt($ch, CURLOPT_TIMEOUT,10); $out = curl_exec($ch); $ret = true; if ($out !== false) { $statuscode = curl_getinfo($ch,CURLINFO_HTTP_CODE); echo "Response Code:" .$statuscode. " "; } curl_close($ch); ?&gt; </code></pre> <p>Actual Ouput</p> <pre><code>Response Code:HTTP/1.1 200 OK ETag: "846caf551746b12e876c0bad5a50830d:1475788950" Last-Modified: Thu, 06 Oct 2016 21:22:30 GMT Accept-Ranges: bytes Content-Length: 17609 Content-Type: text/html Expires: Fri, 21 Sep 2018 15:35:01 GMT Cache-Control: max-age=0, no-cache, no-store Pragma: no-cache Date: Fri, 21 Sep 2018 15:35:01 GMT Connection: keep-alive </code></pre> <p>Expected Output</p> <pre><code>HTTP/1.1 200 OK. </code></pre> <p>Can someone help me with this?</p> </div>


<div class="post-text" itemprop="text"> <p>i'm generating my javascript in PHP. If i include a script tag like this</p> <pre><code>&lt;script src="http://www.everythingpuntagorda.com/blog?ai1ec_render_js=common_backend&amp;amp;is_backend=true&amp;amp;is_calendar_page&amp;amp;ver=1.11.1-pro" type="text/javascript"&gt;&lt;/script&gt; </code></pre> <p>the browser return a 404</p> <p><img src="https://i.stack.imgur.com/Q0CIg.png" alt="enter image description here"></p> <p>but if you go to <a href="http://www.everythingpuntagorda.com/blog?ai1ec_render_js=common_backend&amp;is_backend=true&amp;is_calendar_page&amp;ver=1.11.1-pro" rel="nofollow noreferrer">http://www.everythingpuntagorda.com/blog?ai1ec_render_js=common_backend&amp;is_backend=true&amp;is_calendar_page&amp;ver=1.11.1-pro</a></p> <p>you'll see that the javascript is created as expected. This is our .htaccess</p> <pre><code>DirectoryIndex index.php #BEGIN HG BLOCK #order deny,allow #allow from #allow from #allow from #allow from #allow from #allow from #allow from #allow from #allow from #allow from #allow from #allow from #allow from #deny from all #END HG BLOCK # BEGIN WPSuperCache &lt;IfModule mod_rewrite.c&gt; RewriteEngine On RewriteBase / #If you serve pages from behind a proxy you may want to change 'RewriteCond %{HTTPS} on' to something more sensible AddDefaultCharset UTF-8 RewriteCond %{REQUEST_URI} !^.*[^/]$ RewriteCond %{REQUEST_URI} !^.*//.*$ RewriteCond %{REQUEST_METHOD} !POST RewriteCond %{QUERY_STRING} !.*=.* RewriteCond %{HTTP:Cookie} !^.*(comment_author_|wordpress_logged_in|wp-postpass_).*$ RewriteCond %{HTTP:X-Wap-Profile} !^[a-z0-9\"]+ [NC] RewriteCond %{HTTP:Profile} !^[a-z0-9\"]+ [NC] RewriteCond %{HTTP_USER_AGENT} !^.*(2.0\ MMP|240x320|400X240|AvantGo|BlackBerry|Blazer|Cellphone|Danger|DoCoMo|Elaine/3.0|EudoraWeb|Googlebot-Mobile|hiptop|IEMobile|KYOCERA/WX310K|LG/U990|MIDP-2.|MMEF20|MOT-V|NetFront|Newt|Nintendo\ Wii|Nitro|Nokia|Opera\ Mini|Palm|PlayStation\ Portable|portalmmm|Proxinet|ProxiNet|SHARP-TQ-GX10|SHG-i900|Small|SonyEricsson|Symbian\ OS|SymbianOS|TS21i-10|UP.Browser|UP.Link|webOS|Windows\ CE|WinWAP|YahooSeeker/M1A1-R2D2|iPhone|iPod|Android|BlackBerry9530|LG-TU915\ Obigo|LGE\ VX|webOS|Nokia5800).* [NC] RewriteCond %{HTTP_user_agent} !^(w3c\ |w3c-|acs-|alav|alca|amoi|audi|avan|benq|bird|blac|blaz|brew|cell|cldc|cmd-|dang|doco|eric|hipt|htc_|inno|ipaq|ipod|jigs|kddi|keji|leno|lg-c|lg-d|lg-g|lge-|lg/u|maui|maxo|midp|mits|mmef|mobi|mot-|moto|mwbp|nec-|newt|noki|palm|pana|pant|phil|play|port|prox|qwap|sage|sams|sany|sch-|sec-|send|seri|sgh-|shar|sie-|siem|smal|smar|sony|sph-|symb|t-mo|teli|tim-|tosh|tsm-|upg1|upsi|vk-v|voda|wap-|wapa|wapi|wapp|wapr|webc|winw|winw|xda\ |xda-).* [NC] RewriteCond %{HTTP:Accept-Encoding} gzip RewriteCond %{HTTPS} on RewriteCond %{DOCUMENT_ROOT}/blog/wp-content/cache/supercache/%{SERVER_NAME}/$1/index-https.html.gz -f RewriteRule ^(.*) "/blog/wp-content/cache/supercache/%{SERVER_NAME}/$1/index-https.html.gz" [L] &lt;/IfModule&gt; # END WPSuperCache # BEGIN WordPress &lt;IfModule mod_rewrite.c&gt; RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] &lt;/IfModule&gt; # END WordPress </code></pre> <p>This is the function that generates the javascript</p> <pre><code>/** * Render the javascript for the appropriate page * */ public function render_js() { header( 'Content-Type: application/javascript; charset=utf-8' ); // Aggressive caching to save future requests from the same client. $etag = '"' . md5( __FILE__ . $_GET[self::LOAD_JS_PARAMETER] ) . '"'; header( 'ETag: ' . $etag ); $max_age = 31536000;// One Year header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', Ai1ec_Time_Utility::current_time() + $max_age ) . ' GMT' ); header( 'Cache-Control: public, max-age=' . $max_age ); if ( empty( $_SERVER['HTTP_IF_NONE_MATCH'] ) || $etag !== stripslashes( $_SERVER['HTTP_IF_NONE_MATCH'] ) ) { // compress data if possible if ( true === extension_loaded( 'zlib' ) ) { ob_start( 'ob_gzhandler' ); header( 'Content-Encoding: gzip' ); } else { ob_start(); } $js_path = AI1EC_ADMIN_THEME_JS_PATH . DIRECTORY_SEPARATOR; $common_js = ''; $page_to_load = $_GET[self::LOAD_JS_PARAMETER]; if ( $_GET[self::IS_BACKEND_PARAMETER] === self::TRUE_PARAM ) { $common_js = file_get_contents( $js_path . 'pages/common_backend.js' ); } else if( $page_to_load === self::EVENT_PAGE_JS || $page_to_load === self::CALENDAR_PAGE_JS || $page_to_load === self::LOAD_ONLY_FRONTEND_SCRIPTS ) { if ( $page_to_load === self::LOAD_ONLY_FRONTEND_SCRIPTS &amp;&amp; true === self::$frontend_scripts_loaded ) { return; } if ( false === self::$frontend_scripts_loaded ) { $common_js = file_get_contents( $js_path . 'pages/common_frontend.js' ); self::$frontend_scripts_loaded = true; } } // create the config object for require js $require_config = $this-&gt;create_require_js_config_object(); // load require $require = file_get_contents( $js_path . 'require.js' ); // get jquery $jquery = $this-&gt;get_jquery_version_based_on_browser( $_SERVER['HTTP_USER_AGENT'] ); // load the script for the page $page_js = ''; if ( $page_to_load !== self::LOAD_ONLY_BACKEND_SCRIPTS &amp;&amp; $page_to_load !== self::LOAD_ONLY_FRONTEND_SCRIPTS ) { $page_js = file_get_contents( $js_path . 'pages/' . $page_to_load ); } $translation = $this-&gt;get_frontend_translation_data(); $permalink = get_permalink( $this-&gt;settings-&gt;calendar_page_id ); $translation['calendar_url'] = $permalink; $tranlsation_module = $this-&gt;create_require_js_module( self::FRONTEND_CONFIG_MODULE, $translation ); $config = $this-&gt;create_require_js_module( 'ai1ec_config', $this-&gt;get_translation_data() ); echo $require . $require_config . $tranlsation_module . $config . $jquery . $page_js . $common_js; ob_end_flush(); } else { // Not modified! status_header( 304 ); } // We're done! ai1ec_stop( 0 ); } </code></pre> <p>i had our sysadmin look at this with no effect</p> </div>


<div class="post-text" itemprop="text"> <p>I'm making Single Page Application and I need to <code>prove a concept</code> that I can cache html templates into browser cache and reuse it later on.</p> <p>I have dynamically generated html coming from php, it looks like this:</p> <p></p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code"> <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;!DOCTYPE html&gt; &lt;html &gt; &lt;head&gt; &lt;title&gt;TODO supply a title&lt;/title&gt; &lt;meta charset="UTF-8"&gt; &lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&gt; &lt;script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"&gt;&lt;/script&gt; &lt;script&gt; $(function() { $('#content').load('https://mysite.net.au/index.php?endpoint=get-html-template&amp;template=FirstTemplate&amp;version=1'); }); &lt;/script&gt; &lt;/head&gt; &lt;body id="content"&gt;&lt;/body&gt; &lt;/html&gt;</code></pre> </div> </div> <p>I want to juggle with the urls in this file making it load specific template, utilizing browser cache.</p> <p>If I need to update page template, I would chenge version to 2 or 3 and then it will reload template. To I practically need the html files to be cached forever.</p> <p>This is in theory.</p> <p>On practice, in Google chrome on the network page of developer tools I see </p> <pre><code>jquery-3.3.1.min.js SIZE (from memory cache) index.php?endpoint=get-html-template&amp;template=FirstTemplate&amp;version=1 SIZE 2.2KB </code></pre> <p>So I conclude that html is not being loaded from cache. </p> <p>I tried different <code>Response headers</code></p> <p>my last set looks like this:</p> <pre><code>Cache-control:max-age=31536000 Connection:Keep-Alive Content-Encoding:gzip Content-Length:1721 Content-Type:text/html; charset=UTF-8 Date:Mon, 29 Jan 2018 00:56:01 GMT ETag:"c9c67b-f9f0f-56393377f8681" Expires:Tue, 29 Jan 2019 00:56:01 +0000 Keep-Alive:timeout=5, max=99 Last-Modified:Mon, 29 Jan 2018 00:27:57 +0000 Server:Apache/2.2.34 (Unix) mod_ssl/2.2.34 OpenSSL/1.0.2l DAV/2 PHP/5.6.30 status:200 Vary:Accept-Encoding x-cache:HIT X-Powered-By:PHP/5.6.30 </code></pre> <p>Is there something I don't take to account? I use Chrome 63 for Mac OS.</p> </div>


<div class="post-text" itemprop="text"> <p>I am having a problem with a POSTed binary stream "growing" in transit/upon reception between an AngularJS app and a PHP backend.</p> <p>The POST is pretty common to what I've done elsewhere...however, this mixes text and binary data... I'm not sure if this is sufficient...</p> <pre><code> var req = { method: 'POST', url: 'putInitialPicture.php', data : { "xuserid" : $scope.user.id, "xauthtoken" : $scope.user.authtoken, "data" : picdata } }; console.log("posting...."); $http(req) .success(function (data, status, headers, config) { console.log("returned from post"); console.log(data); $scope.sync($scope.user.id); }) .error(function(data, status, headers, config) { console.log("error result"); console.log(data); }); </code></pre> <p>In the PHP code on the receiving function, I do the normal</p> <pre><code> $postdata = file_get_contents("php://input"); $_POST = json_decode($postdata, true); </code></pre> <p>to obtain the posted data</p> <p>Later in the script, after validations are performed, and the destination filename is determined the data is written out with a simple</p> <pre><code> file_put_contents("$basename/$fname",$_POST['data']); </code></pre> <p>This is where things get... interesting.</p> <p>The written file (an image file - a JPG) is not the same as I read on the Angular side. The file (as reported by Angular code that reads the data) is 5727 bytes.</p> <p>The size on disk, after the data is POSTed, decoded, and written to disk by PHP, is 9992 bytes.</p> <p>Somewhere between the server, the client and the server, it has not quite doubled. I can discount the initial GET operation, as the content being retrieved is being reported as the correct size.</p> <p>It would seem that somewhere in the POST there's something happening to the binary stream to make it able to be sent that is more than a simple JSON decode is able to handle.... but I cant figure out what.</p> <p>Is there a Header I need to set on the POST to have the webserver decode the data properly? or is there an additional decoding of the $_POST['data'] object needed prior to use?</p> <p>I'm not sure what to try next here.. the questions/answers I google are all simple text... not a combination text/binary post.</p> <p><strong>EDIT - Solution - sort of</strong></p> <p>Sending the binary data is just a bad idea. Instead I opted for reuse of an Upload service I already had working. This required creation of a File object (more generically a blob) that I could toss the bytes downloaded from the remote server into, resulting in:</p> <pre><code> $scope.CreateBlob = function(Data, contentType) { contentType = contentType || ''; var sliceSize = 1024; var byteCharacters = Data; var bytesLength = byteCharacters.length; var slicesCount = Math.ceil(bytesLength / sliceSize); var byteArrays = new Array(slicesCount); for (var sliceIndex = 0; sliceIndex &lt; slicesCount; ++sliceIndex) { var begin = sliceIndex * sliceSize; var end = Math.min(begin + sliceSize, bytesLength); var bytes = new Array(end - begin); for (var offset = begin, i = 0 ; offset &lt; end; ++i, ++offset) { bytes[i] = byteCharacters[offset].charCodeAt(0); } byteArrays[sliceIndex] = new Uint8Array(bytes); } return new Blob(byteArrays, { type: contentType }); } </code></pre> <p>and replacing the $http.post(...) with</p> <pre><code> var blob = $scope.CreateBlob( picdata ,"image/jpg"); $scope.files = []; $scope.files.push(blob); </code></pre> <p>Already having a $watch set on $scope.files the upload "just happens".</p> <p>The weird thing now though... the $http.get(...) returns a picdata string that is shorter than the server says it is. According to the headers, the length the image should be 5886 bytes...</p> <p><strong>Accept-Ranges:bytes<br> Cache-Control:max-age=84600, public, no-transform<br> Content-Length:5886<br> Content-Type:image/jpeg<br> Date:Sun, 27 Sep 2015 04:06:10 GMT<br> ETag:"c01bf-16fe-520b2957e00e9"<br> Expires:Mon, 28 Sep 2015 03:36:10 GMT<br> Last-Modified:Sun, 27 Sep 2015 03:57:47 GMT<br> Server:Apache/2.2.22 (Debian)</strong> </p> <p>However, when I log the <strong>picdata.length</strong> I'm getting <strong>5727 bytes</strong> </p> <p>Different problem.. different day..</p> </div>


<div class="post-text" itemprop="text"> <p>Everything started when I was trying to improve the loading times of thumbnail pictures in a gallery of sort i have. the paths of all images come from a JSON file/string/response along with several details about them, in order to build the UI.</p> <p>My first thought was to cache them with JavaScript itself:</p> <pre><code>for( let i = 0; i &lt; data.length; i++ ) { let thumbnail = new Image(); thumbnail.src = data[ i ].thumbnail; } </code></pre> <blockquote> <p>ES2015 with BabelJS being used</p> </blockquote> <p>I know it's not the best approach as I should load them on demand (i.e. when accessing their offsets in JSON) or even asynchronously with AJAX. In fact I did try both ways too, but I didn't manage to make the other data wait for the image to be fully loaded before fill the UI.</p> <p>But this is a matter for later ^_^</p> <p>So, I checked the Chrome Inspector and under <em>Network</em> tab all JPG were being loaded as expected but when actually using the images, modifying the <code>src</code> attribute of the container designed for the preview (see below), every image was being loaded again.</p> <pre><code>$( 'figure img' ).attr( 'src', data[ current ].thumbnail ); </code></pre> <blockquote> <p>This is just a fragment. 'current' is the gallery counter to navigate through the JSON</p> </blockquote> <p>After exhausting my testing skills I ended up believing the issue was my server.</p> <p>I'm currently using PHP Internal Webserver for development because, at least until now, I didn't have the need of a complete server solution. It's bad to have several <em>command-line</em> windows opened, but anyway...</p> <p>For the record, the webserver is started like this:</p> <pre><code>php.exe -c "path\to\php.ini" -S "" -t "." "routing.php" </code></pre> <blockquote> <p>Running under Windows environment &gt;.&lt;</p> </blockquote> <p>My previous routing file was very blunt, just returning <code>false</code> if requesting an image, js, css, font... so, after reading several topics in here, I changed it trying to include some caching:</p> <pre><code>&lt;?php if( preg_match( '/\.(js|ico|gif|jpg|png|css|eot|svg|ttf|woff|php)$/', $_SERVER["REQUEST_URI"] ) ) { date_default_timezone_set( 'America/Sao_Paulo' ); $file = sprintf( '.%s', $_SERVER['REQUEST_URI'] ); if( ! file_exists( $file ) ) { header( 'HTTP/1.1 404 Not Found' ); } $eTag = md5_file( $file ); if( $eTag !== FALSE ) { header( 'Etag: ' . $eTag ); } header( 'Cache-Control: public, max-age=2592000' ); $mTime = filemtime( $file ); if( $mTime !== FALSE ) { $GMD = gmdate('D, d M Y H:i:s', $mTime ); header( sprintf( 'Last-Modified: %s GMT', $GMD ) ); if( isset( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) { $mSince = strtotime( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ); if( $mSince !== FALSE &amp;&amp; $mSince == $GMD ) { header( 'HTTP/1.1 304 Not Modified' ); return false; } } if( isset( $_SERVER['HTTP_IF_NONE_MATCH'] ) ) { $noneMatch = str_replace( '"', '', stripslashes( $_SERVER['HTTP_IF_NONE_MATCH'] ) ); if( $noneMatch == md5( $file . $mTime ) ) { header( 'HTTP/1.1 304 Not Modified' ); return false; } if( $noneMatch == $eTag ) { header( 'HTTP/1.1 304 Not Modified' ); return false; } } } // Resource not cached yet header( 'Content-Type: ' . mime_content_type( $file ) ); header( 'Content-Length: ' . filesize( $file ) ); return false; } include __DIR__ . '/index.php'; </code></pre> <p>The performance was considerably better but, testing with one single file, directly, the first load took ~300ms, the second ~5ms, the third ~300ms, the fourth ~5ms and so on. o.O</p> <p>Then I tested it in the whole Application and the caching problem persisted, although, theoretically, the images were already loaded with JavaScript and stored in the Image Object, they were loaded once again when their respective offset in the JSON was accessed through the navigation.</p> <p>Also, when refreshing the page multiple times I didn't have the same "jumping" response times as with direct access. everything not coming from CDNs (jQuery, Bootstrap...) were being loaded again, again and again. &gt;:(</p> <p>After more research, two of the culprits I've found were the <code>Cache-control</code> not being set and the overall status code.</p> <p>I couldn't find a way to send the <code>304 Header</code> using the PHP Internal WebServer, not because I don't know how, afterall the code is the same, but because all implementations I've seen depends on some <code>$_SERVER</code> entries that, as far as I know, are provided by Apache (and maybe other dedicated server applications).</p> <p>Also, for some reason, in Chrome Inspector, opening the <em>Headers</em> section of a resource, I don't see in there the <code>Cache-control</code> directive under <em>Response Headers</em> even though I did set it, as you can see, with ~30 days of expiration.</p> <p>More than how could I solve these issue I would like to understand why is this happening.</p> </div>


今年,我也32了 ,为了不给大家误导,咨询了猎头、圈内好友,以及年过35岁的几位老程序员……舍了老脸去揭人家伤疤……希望能给大家以帮助,记得帮我点赞哦。 目录: 你以为的人生 一次又一次的伤害 猎头界的真相 如何应对互联网行业的「中年危机」 一、你以为的人生 刚入行时,拿着傲人的工资,想着好好干,以为我们的人生是这样的: 等真到了那一天,你会发现,你的人生很可能是这样的: ...




一、分而治之的思想 分而治之方法与软件设计的模块化方法非常相似 分而治之通常不用于解决问题的小实例,而要解决一个问题的大实例。一般步骤为: ①把一个大实例分为两个或多个更小的实例 ②分别解决每个小实例 ③把这些小实例的解组合成原始大实例的解 二、实际应用之找出假币 问题描述 一个袋子有16个硬币,其中只有一个是假币,这个假币比其他的真币重量轻(其他所有真币的重量都是相同的)...


一 前言 此篇文章的内容也是学习不久,终于到周末有时间码一篇文章分享知识追寻者的粉丝们,学完本篇文章,读者将对token类的登陆认证流程有个全面的了解,可以动态搭建自己的登陆认证过程;对小项目而已是个轻量级的认证机制,符合开发需求;更多精彩原创内容关注公主号知识追寻者,读者的肯定,就是对作者的创作的最大支持; 二 jwt实现登陆认证流程 用户使用账号和面发出post请求 服务器接受到请求后使用私...

技术大佬:我去,你写的 switch 语句也太老土了吧

昨天早上通过远程的方式 review 了两名新来同事的代码,大部分代码都写得很漂亮,严谨的同时注释也很到位,这令我非常满意。但当我看到他们当中有一个人写的 switch 语句时,还是忍不住破口大骂:“我擦,小王,你丫写的 switch 语句也太老土了吧!” 来看看小王写的代码吧,看完不要骂我装逼啊。 private static String createPlayer(PlayerTypes p...


刚才邻居打了个电话说:喂小灰,你家wifi的密码是多少,我怎么连不上了。 我。。。 我也忘了哎,就找到了一个好办法,分享给大家: 第一种情况:已经连接上的wifi,怎么知道密码? 打开:控制面板\网络和 Internet\网络连接 然后右击wifi连接的无线网卡,选择状态 然后像下图一样: 第二种情况:前提是我不知道啊,但是我以前知道密码。 此时可以利用dos命令了 1、利用netsh wlan...




提到“程序员”,多数人脑海里首先想到的大约是:为人木讷、薪水超高、工作枯燥…… 然而,当离开工作岗位,撕去层层标签,脱下“程序员”这身外套,有的人生动又有趣,马上展现出了完全不同的A/B面人生! 不论是简单的爱好,还是正经的副业,他们都干得同样出色。偶尔,还能和程序员的特质结合,产生奇妙的“化学反应”。 @Charlotte:平日素颜示人,周末美妆博主 大家都以为程序媛也个个不修边幅,但我们也许...






私下里,有不少读者问我:“二哥,如何才能写出一份专业的技术简历呢?我总感觉自己写的简历太烂了,所以投了无数份,都石沉大海了。”说实话,我自己好多年没有写过简历了,但我认识的一个同行,他在阿里,给我说了一些他当年写简历的方法论,我感觉太牛逼了,实在是忍不住,就分享了出来,希望能够帮助到你。 01、简历的本质 作为简历的撰写者,你必须要搞清楚一点,简历的本质是什么,它就是为了来销售你的价值主张的。往深...




即将毕业的应届毕业生一枚,现在只拿到了两家offer,但最近听到一些消息,其中一个offer,我这个组据说客户很少,很有可能整组被裁掉。 想问大家: 如果我刚入职这个组就被裁了怎么办呢? 大家都是什么时候知道自己要被裁了的? 面试软技能指导: BQ/Project/Resume 试听内容: 除了刷题,还有哪些技能是拿到offer不可或缺的要素 如何提升面试软实力:简历, 行为面试,沟通能...


场景 日常开发,if-else语句写的不少吧??当逻辑分支非常多的时候,if-else套了一层又一层,虽然业务功能倒是实现了,但是看起来是真的很不优雅,尤其是对于我这种有强迫症的程序"猿",看到这么多if-else,脑袋瓜子就嗡嗡的,总想着解锁新姿势:干掉过多的if-else!!!本文将介绍三板斧手段: 优先判断条件,条件不满足的,逻辑及时中断返回; 采用策略模式+工厂模式; 结合注解,锦...


如果世界上都是这种不思进取的软件公司,那别说大部分程序员只会写 3 年代码,恐怕就没有程序员这种职业。

离职半年了,老东家又发 offer,回不回?

有小伙伴问松哥这个问题,他在上海某公司,在离职了几个月后,前公司的领导联系到他,希望他能够返聘回去,他很纠结要不要回去? 俗话说好马不吃回头草,但是这个小伙伴既然感到纠结了,我觉得至少说明了两个问题:1.曾经的公司还不错;2.现在的日子也不是很如意。否则应该就不会纠结了。 老实说,松哥之前也有过类似的经历,今天就来和小伙伴们聊聊回头草到底吃不吃。 首先一个基本观点,就是离职了也没必要和老东家弄的苦...


阿里巴巴全球数学竞赛( Alibaba Global Mathematics Competition)由马云发起,由中国科学技术协会、阿里巴巴基金会、阿里巴巴达摩院共同举办。大赛不设报名门槛,全世界爱好数学的人都可参与,不论是否出身数学专业、是否投身数学研究。 2020年阿里巴巴达摩院邀请北京大学、剑桥大学、浙江大学等高校的顶尖数学教师组建了出题组。中科院院士、美国艺术与科学院院士、北京国际数学...


不知道是不是只有我这样子,还是你们也有过类似的经历。 上学的时候总有很多光辉历史,学年名列前茅,或者单科目大佬,但是虽然慢慢地长大了,你开始懈怠了,开始废掉了。。。 什么?你说不知道具体的情况是怎么样的? 我来告诉你: 你常常潜意识里或者心理觉得,自己真正的生活或者奋斗还没有开始。总是幻想着自己还拥有大把时间,还有无限的可能,自己还能逆风翻盘,只不是自己还没开始罢了,自己以后肯定会变得特别厉害...






当HR压你价,说你只值7K时,你可以流畅地回答,记住,是流畅,不能犹豫。 礼貌地说:“7K是吗?了解了。嗯~其实我对贵司的面试官印象很好。只不过,现在我的手头上已经有一份11K的offer。来面试,主要也是自己对贵司挺有兴趣的,所以过来看看……”(未完) 这段话主要是陪HR互诈的同时,从公司兴趣,公司职员印象上,都给予对方正面的肯定,既能提升HR的好感度,又能让谈判气氛融洽,为后面的发挥留足空间。...


HashMap底层实现原理,红黑树,B+树,B树的结构原理 Spring的AOP和IOC是什么?它们常见的使用场景有哪些?Spring事务,事务的属性,传播行为,数据库隔离级别 Spring和SpringMVC,MyBatis以及SpringBoot的注解分别有哪些?SpringMVC的工作原理,SpringBoot框架的优点,MyBatis框架的优点 SpringCould组件有哪些,他们...


硅谷科技公司上班时间OPEN早已不是什么新鲜事,早九晚五是常态,但有很多企业由于不打卡,员工们10点、11点才“姗姗来迟”的情况也屡见不鲜。 这种灵活的考勤制度为人羡慕,甚至近年来,国内某些互联网企业也纷纷效仿。不过,硅谷普遍弹性的上班制度是怎么由来的呢?这种“流行性迟到”真的有那么轻松、悠哉吗? 《动态规划专题班》 课程试听内容: 动态规划的解题要领 动态规划三大类 求最值/计数/可行性 常...




爬取彼岸桌面网站较为简单,用到了requests、lxml、Beautiful Soup4


编程语言层出不穷,从最初的机器语言到如今2500种以上的高级语言,程序员们大呼“学到头秃”。程序员一边面临编程语言不断推陈出新,一边面临由于许多代码已存在,程序员编写新应用程序时存在重复“搬砖”的现象。 无代码/低代码编程应运而生。无代码/低代码是一种创建应用的方法,它可以让开发者使用最少的编码知识来快速开发应用程序。开发者通过图形界面中,可视化建模来组装和配置应用程序。这样一来,开发者直...

面试了一个 31 岁程序员,让我有所触动,30岁以上的程序员该何去何从?





已经连续五年参加大厂校招、社招的技术面试工作,简历看的不下于万份 这篇文章会用实例告诉你,什么是差的程序员简历! 疫情快要结束了,各个公司也都开始春招了,作为即将红遍大江南北的新晋UP主,那当然要为小伙伴们做点事(手动狗头)。 就在公众号里公开征简历,义务帮大家看,并一一点评。《启舰:春招在即,义务帮大家看看简历吧》 一石激起千层浪,三天收到两百多封简历。 花光了两个星期的所有空闲时...


前几天我们公司做了一件蠢事,非常非常愚蠢的事情。我原以为从学校出来之后,除了找工作有测试外,不会有任何与考试有关的事儿。 但是,天有不测风云,公司技术总监、人事总监两位大佬突然降临到我们事业线,叫上我老大,给我们组织了一场别开生面的“考试”。 那是一个风和日丽的下午,我翘着二郎腿,左手端着一杯卡布奇诺,右手抓着我的罗技鼠标,滚动着轮轴,穿梭在头条热点之间。 “淡黄的长裙~蓬松的头发...


导读 前天面试了一个985高校的实习生,问了他平时用什么开发工具,他想也没想的说IDEA,于是我抛砖引玉的问了一下IDEA的调试用过吧,你说说怎么设置断点...

都前后端分离了,咱就别做页面跳转了!统统 JSON 交互

文章目录1. 无状态登录1.1 什么是有状态1.2 什么是无状态1.3 如何实现无状态1.4 各自优缺点2. 登录交互2.1 前后端分离的数据交互2.2 登录成功2.3 登录失败3. 未认证处理方案4. 注销登录 这是本系列的第四篇,有小伙伴找不到之前文章,松哥给大家列一个索引出来: 挖一个大坑,Spring Security 开搞! 松哥手把手带你入门 Spring Security,别再问密...