返回文件流,问价不存在,第一次报错,第二次才404

W

1、先执行以下文件存在代码,没有问题
<?php
namespace app\controller;

use support\Request;

class FooController
{
public function hello(Request $request)
{
return response()->file(public_path() . '/favicon.ico');
}
}
2、再修改为以下不存在的文件代码,第一次执行报错,第二次执行才是404
<?php
namespace app\controller;

use support\Request;

class FooController
{
public function hello(Request $request)
{
return response()->file(public_path() . '/favicon888.ico');
}
}

334 1 0
1个回答

W

返回文件流,文件不存在,第一次报错,第二次才404

  • W 2023-06-20

    ErrorException: filemtime(): stat failed for D:\www.workerman.net\webman\public/favicon8.ico in D:\www.workerman.net\webman\vendor\workerman\webman-framework\src\Http\Response.php:69
    Stack trace:

    0 [internal function]: support\App::{closure}(2, 'filemtime(): st...', 'D:\www.workerma...', 69, Array)

    1 D:\www.workerman.net\webman\vendor\workerman\webman-framework\src\Http\Response.php(69): filemtime('D:\www.workerma...')

    2 D:\www.workerman.net\webman\vendor\workerman\webman-framework\src\Http\Response.php(40): Webman\Http\Response->notModifiedSince('D:\www.workerma...')

    3 D:\www.workerman.net\webman\app\controller\UserController.php(12): Webman\Http\Response->file('D:\www.workerma...')

    4 D:\www.workerman.net\webman\vendor\workerman\webman-framework\src\App.php(319): app\controller\UserController->hello(Object(support\Request))

    5 D:\www.workerman.net\webman\vendor\workerman\webman-framework\src\App.php(168): Webman\App::Webman{closure}(Object(support\Request))

    6 D:\www.workerman.net\webman\vendor\workerman\workerman\Connection\TcpConnection.php(646): Webman\App->onMessage(Object(Workerman\Connection\TcpConnection), Object(support\Request))

    7 D:\www.workerman.net\webman\vendor\workerman\workerman\Events\Select.php(311): Workerman\Connection\TcpConnection->baseRead(Resource id #107)

    8 D:\www.workerman.net\webman\vendor\workerman\workerman\Worker.php(1479): Workerman\Events\Select->loop()

    9 D:\www.workerman.net\webman\vendor\workerman\workerman\Worker.php(1399): Workerman\Worker::forkWorkersForWindows()

    10 D:\www.workerman.net\webman\vendor\workerman\workerman\Worker.php(560): Workerman\Worker::forkWorkers()

    11 D:\www.workerman.net\webman\vendor\workerman\webman-framework\src\support\App.php(131): Workerman\Worker::runAll()

    12 D:\www.workerman.net\webman\start.php(4): support\App::run()

    13 {main}

  • Gin 2023-06-20

    首先你文件不存在 filemtime肯定报错啊 自己判断下文件在不在

  • W 2023-06-20

    那为什么第一次访问报错,第二次访问才出现404;按照官方文档应该第一次访问就是自动返回404.如果文件不存在,会自动转为404响应

  • Gin 2023-06-20

    复现了一次, 应该是bug

🔝