PHP Heroku -错误代码H10(状态503)

xj3cbfub  于 2022-11-13  发布在  PHP
关注(0)|答案(1)|浏览(141)

我在Heroku上部署了一个简单的PHP应用程序,其中只包含一个PHP脚本作为源代码。我决定在一个单独的PHP脚本中编写一个函数。在此之后,我得到了一个403 Forbidden Error,并且在我的应用程序的url上显示了以下消息:Forbidden You don't have permission to access / on this server。因此,我创建了一个名为Procfile的文本文档,没有任何扩展名,并在其中发布了以下内容:web: vendor/bin/heroku-php-apache2 web/ .
但是,现在我在heroku logs上遇到以下错误:

2018-04-10T09:09:09.853483+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=POST path="/" host=************.herokuapp.com request_id=************ fwd="************" dyno= connect= service= status=503 bytes= protocol=https
2018-04-10T09:09:56.037642+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=************.herokuapp.com request_id=************ fwd="************" dyno= connect= service= status=503 bytes= protocol=https

并且在我的应用程序的URL处显示以下消息:

Application error
An error occurred in the application and your page could not be served. 
If you are the application owner, check your logs for details.

我在Heroku上的(main)PHP脚本从Dialogflow接收/托管一个webhook,并返回一些从数据库中检索到的信息给它。

<?php

$dbServername = '******************';
$dbUsername = '******************';
$dbPassword = '******************';
$dbName = '******************';
$conn = mysqli_connect($dbServername, $dbUsername, $dbPassword, $dbName);

header('Content-Type: application/json');
$method = $_SERVER['REQUEST_METHOD'];

if ($method == 'POST') {
    $requestBody = file_get_contents('php://input');
    $json = json_decode($requestBody);

    $action = $json->result->action;
    $first_name = $json->result->contexts[0]->parameters->{'given-name'};
    $last_name = $json->result->contexts[0]->parameters->{'last-name'};
    $lifespan = $json->result->contexts[0]->lifespan;

    $sql = "SELECT * FROM family WHERE name LIKE '%$first_name%$last_name%';";
    $result = mysqli_query($conn, $sql);
    $resultCheck = mysqli_num_rows($result);
    if ($resultCheck > 0) {
        while ($row = mysqli_fetch_assoc($result)) {
            $person = $row;
        }

        switch ($action) {
            case 'Name':
                $speech = "$first_name is my" . $person["name"] . ".";
                break;
            case 'Location':
                $speech = "$first_name is living in {$person["location"]}.";
                break;
            default:
                $speech = "Please ask me something more relevant to my family";
                break;
        }
    } else {

        $speech = "Sorry, $first_name $last_name is not a member of my family.";
    }

    $response = new \stdClass();
    $response->speech = $speech;
    $response->displayText = $speech;
    $response->source = "agent";
    echo json_encode($response);
} else {
    echo "Method not allowed";
}
?>

为什么会出现此错误,如何修复此错误?

我不知道这是否相关,但当我在终端输入git push heroku master时,我也收到以下警告:

remote:  !     WARNING: Your Composer vendor dir is part of your Git repository.
remote:        This directory should not be under version control; only your
remote:        'composer.json' and 'composer.lock' files should be added, which
remote:        will let Composer handle installation of dependencies on deploy.
jfgube3f

jfgube3f1#

我通过检查根目录是否存在解决了同样的问题。您需要检查Procfile

相关问题