php - 503 表单提交时服务不可用

标签 php mysql laravel amazon-web-services

我使用 PHP Laravel 和 Vue JS 创建了一个项目。并配置了亚马逊AWS的基本计划。一开始,它运行良好,没有任何问题。但现在,当我尝试添加新的博客文章或编辑内容较多的已有博客文章时,它显示 503 服务不可用错误。我为博客开发了如下所示的算法。

表格:

  1. blogs - This table is used to store lightweight data of the post like title, featured image, URL, etc.

  2. posts - This table is used to store the actual content of the post. It contains three columns like blog id, content, order. Here I am using text datatype for content which will accept nearly 70k characters.

算法: 当我提交博客文章时,它首先会在博客表中创建一行包含轻量级数据的行。之后,实际的帖子内容将被分割成一个数组,每个项目包含 65k 个字符。每个项目都将作为新行存储在 posts 表中,并在 blogs 表中创建博客 ID。在检索帖子时,它将连接帖子表中的行并显示实际的帖子。

注意:上述过程运行良好,没有任何问题。

问题: 实际的问题是,当我尝试添加新帖子或使用图像编辑现有帖子(产生大量字符)时,它突然开始显示 503 错误,即使帖子是在博客表中创建的,并且添加的字符量不完整在 posts 表中,在添加其余内容时显示 503 错误。

注意:即使它在我的本地主机和另一个 Bluehost 服务器上也运行良好。

我尝试将内容拆分减少为 25k 个字符,但结果显示相同。

if($request->hasFile('image')) {
            $filenameWithExt = $request->file('image')->getClientOriginalName();
            $filename = pathinfo($filenameWithExt, PATHINFO_FILENAME);
            $extension = $request->file('image')->getClientOriginalExtension();
            $fileNameToStore = 'post_' . time() . '.' .$extension;
            $path = public_path('uploads/posts/' . $fileNameToStore);
            if(!file_exists(public_path('uploads/posts/'))) {
                mkdir(public_path('uploads/posts/'), 0777);
            }
            Image::make($request->file('image')->getRealPath())->resize(900, NULL)->save($path);
        }else {
            $fileNameToStore = NULL;
        }

        if($request->hasFile('author_image')) {
            $filenameWithExt = $request->file('author_image')->getClientOriginalName();
            $filename = pathinfo($filenameWithExt, PATHINFO_FILENAME);
            $extension = $request->file('author_image')->getClientOriginalExtension();
            $authorImage = 'author_' . time() . '.' .$extension;
            $path = public_path('uploads/authors/' . $authorImage);
            if(!file_exists(public_path('uploads/authors/'))) {
                mkdir(public_path('uploads/authors/'), 0777);
            }
            Image::make($request->file('author_image')->getRealPath())->resize(50, 50)->save($path);
        }else {
            $authorImage = NULL;
        }

        $blog = Blog::create([
            'title' => $request->title,
            'image' => $fileNameToStore,
            'category' => $request->category,
            'meta_description' => $request->meta_description,
            'meta_keywords' => $request->meta_keywords,
            'url' => $request->url,
            'meta_title' => $request->meta_title,
            'author_name' => $request->author_name,
            'author_image' => $authorImage,
            'author_linkedin' => $request->author_linkedin,
            'popular' => $request->popular
        ]);

        $contents = str_split($request->post, 65000);
        $i = 1;
        foreach($contents as $key => $item)
        {
            Post::create([
                'post' => $blog->id,
                'content' => $item,
                'order' => $i
            ]);

            $i++;
        }

我希望输出重定向回博客页面,并显示成功消息“帖子已成功创建”,但实际结果是

服务不可用 由于维护停机或容量问题,服务器暂时无法满足您的请求。请稍后重试。

最佳答案

看来您需要增加 php.inipost_max_sizeupload_max_filesize 的值。 AWS 指南:https://aws.amazon.com/ru/premiumsupport/knowledge-center/wordpress-themes-2mb/

我还建议您针对您的情况使用交易。这将有助于避免部分创建的帖子。 https://laravel.com/docs/5.8/database#database-transactions

关于php - 503 表单提交时服务不可用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58553873/

相关文章:

php - artisan 迁移访问被拒绝

laravel - 路由分组和命名空间

mysql - 在 laravel 中扩展 MySqlGrammar 并绑定(bind)到 IOC 的正确方法是什么

php - 如何在数据库中获取和存储时间戳

php - 如何在 PHP 中使用 dotall 修饰符指定行尾?

php - 从多列mysql中选择值

mysql - 将 Rails/Unicorn/Nginx 容器连接到 MySQL 容器

mysql - 纠正mysql语法错误

PHP/MySQL 以错误的顺序回显并且还回显列标题而不是该列的行值?

php - 如果单击链接,此 PHP 代码应该如何过滤掉显示的 SQL 行?