Skip to content

ControllerJson JSON控制器

WARNING

开启调试模式时,接口会返回详细的异常服务和信息
生产环境请一定要关闭调试模式

bash
curl http://your-domian/your-entrance/health

# 服务异常
HTTP/1.1 500 Internal Server Error
Content-Type: text/html

{"CheckEnv":"APP_DEBUG is not falsy","CheckCache":"health_check_cache_key is not set"}

实例化

php
new \think\health\Controller\ControllerJson(
    /**
     * 正常状态码
     * @var int
     */
    successStatusCode: 200,
    /**
     * 异常状态码
     * @var int
     */
    errorStatusCode: 500,
    /**
     * 是否显示异常信息
     * @var bool
     */
    showErrorMessage: false,
)

参数说明

参数类型是否必传默认值说明
successStatusCodeinteger200正常状态码
errorStatusCodeinteger500异常状态码
showErrorMessagebooleanfalse是否显示异常信息

请求示例

bash
curl http://your-domian/your-entrance/health

# 服务正常
HTTP/1.1 200 OK
Content-Type: text/html

{"CheckDataBase":"ok","CheckEnv":"ok",...}

# 服务异常
HTTP/1.1 500 Internal Server Error
Content-Type: text/html

{"CheckDataBase":"error","CheckEnv":"error",...}