小编car*_*lve的帖子

Laravel标头和PHP缓存

我的laravel4应用程序中有一个小型图像生成器。生成图像大约需要700毫秒,因此我开始在服务器上缓存生成的结果,并将其返回给浏览器,这样可以节省一些时间。

由于图像一旦生成就永远不会改变,所以我想告诉浏览器在本地缓存图像,并使用以下代码完成了此操作:

$path = $cacheFolderPath . $cacheFileName;

if (File::exists( $path )){
    $response = Response::make(File::get($path));
    $response->header('Content-Type', 'image/png');
    $response->header('Content-Disposition', 'inline; filename="'.$cacheFileName.'"');
    $response->header('Content-Transfer-Encoding', 'binary');
    $response->header('Cache-Control', 'public, max-age=10800, pre-check=10800');
    $response->header('Pragma', 'public');
    $response->header('Expires', date(DATE_RFC822,strtotime(" 2 day")) );
    $response->header('Last-Modified', date(DATE_RFC822, File::lastModified($path)) );
    $response->header('Content-Length', filesize($path));
    return $response;
}
Run Code Online (Sandbox Code Playgroud)

这会将带有状态代码的图像发送200 OK到带有以下标头的浏览器:

Cache-Control:max-age=10800, pre-check=10800, public
Connection:Keep-Alive
Content-Disposition:inline; filename="pie_0_normal.png"
Content-Length:2129
Content-Transfer-Encoding:binary
Content-Type:image/png
Date:Wed, 07 Aug 2013 10:29:20 GMT
Expires:Fri, 09 Aug 13 10:29:20 +0000
Keep-Alive:timeout=5, max=93
Last-Modified:Wed, 07 Aug 13 10:14:42 +0000
Pragma:public
Server:Apache/2.4.3 (Win32) OpenSSL/1.0.1c PHP/5.4.7
Set-Cookie:laravel_session=767487mhf6j2btv3k01vu56174; …
Run Code Online (Sandbox Code Playgroud)

php http-caching http-headers laravel laravel-4

5
推荐指数
1
解决办法
8461
查看次数

不在array_walk中的对象上下文错误时使用$ this

我在使用array_walk类中的闭包时遇到了一个奇怪的问题.在我的开发环境中使用php版本5.4.7不会出现这个问题,但它在我的部署环境5.3.3中会出现.

以下代码在我的生产框上运行正常,但在我的部署环境中崩溃:

<?php
    error_reporting(-1);

    Class TestArrayWalk
    {
        /** @var null|array */
        protected $userInput = null;

        /**
         * This expects to be passed an array of the users input from
         * the input fields.
         *
         * @param  array $input
         * @return void
         */
        public function setUserInput( array $input )
        {
            $this->userInput = $input;

            // Lets explode the users input and format it in a way that this class
            // will use for marking
            array_walk( $this->userInput, …
Run Code Online (Sandbox Code Playgroud)

php

5
推荐指数
1
解决办法
2023
查看次数

在Azure Web应用程序中使用重写规则获取权限错误

我有一个基于Laravel 4的PHP应用程序,我已经成功地在Azure Web应用程序中工作,我遇到的唯一问题是当我尝试访问文件时,example.azurewebsites.net/js/vendor/jquery.slicknav.min.js我得到"您无权查看此目录或页面. " 响应.

该文件夹site/wwwroot是我放置所有Laravel应用程序文件的地方,对于那些不熟悉Laravel的人,它包含四个文件夹:app,Bootstrap,public和vendor.

我已在Azure门户中设置虚拟应用程序和目录设置,以映射/site\wwwroot\public公共目录并在其中放置web.config文件,其中包含以下内容:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.webServer>
        <urlCompression doDynamicCompression="true" doStaticCompression="true" dynamicCompressionBeforeCache="true"/>
        <staticContent>
            <remove fileExtension=".svg" />
            <mimeMap fileExtension=".svg" mimeType="image/svg+xml" />
            <mimeMap fileExtension=".woff" mimeType="application/font-woff" />
            <clientCache httpExpires="Sun, 29 Mar 2020 00:00:00 GMT" cacheControlMode="UseExpires" />
        </staticContent>
        <httpProtocol>
            <customHeaders>
                <add name="Strict-Transport-Security" value="max-age=31536000; includeSubDomains"/>
                <add name="Access-Control-Allow-Origin" value="*" />
                <add name="Access-Control-Allow-Headers" value="X-Requested-With,Content-Type" />
                <add name="Access-Control-Allow-Methods" value="POST,GET,OPTIONS,DELETE,PUT,PATCH" />
            </customHeaders>
        </httpProtocol>
        <rewrite>
            <rules>
                <rule name="Laravel4" stopProcessing="true">
                    <match url="^" ignoreCase="false" />
                    <conditions logicalGrouping="MatchAll">
                        <add …
Run Code Online (Sandbox Code Playgroud)

php azure azure-web-sites azure-app-service-envrmnt

3
推荐指数
1
解决办法
1911
查看次数