ThinkPHP 3.2.x 将错误发出头部改为 503 的方法
ThinkPHP 3.2.x 将异常发出头部改为 503 的方法
如果程序发生异常,thinkphp默认都是抛出 404 头。
ThinkPHP3.2.3相关代码:
#/ThinkPHP/Library/Think/Think.class.php /** * 自定义异常处理 * @access public * @param mixed $e 异常对象 */ static public function appException($e) { $error = array(); $error['message'] = $e->getMessage(); $trace = $e->getTrace(); if('E'==$trace[0]['function']) { $error['file'] = $trace[0]['file']; $error['line'] = $trace[0]['line']; }else{ $error['file'] = $e->getFile(); $error['line'] = $e->getLine(); } $error['trace'] = $e->getTraceAsString(); Log::record($error['message'],Log::ERR); // 发送404信息 header('HTTP/1.1 404 Not Found'); header('Status:404 Not Found'); self::halt($error); }
404表示的是未找到,发生异常却抛出404 HTT 头,其实是错误的。
应该修改为 503 头最合适,修改方法,将 header部分修改为如下:
header('HTTP/1.1 503 Service Unavailable'); header('Status: 503 Service Unavailable');
相关:《百度搜索引擎工作原理》
[url]http://zhanzhang.baidu.com/college/courseinfo?id=144[/url]
2、常用抓取返回码示意 简单介绍几种百度支持的返回码: 1)最常见的404代表“NOT FOUND”,认为网页已经失效,通常将在库中删除,同时短期内如果spider再次发现这条url也不会抓取; 2)503代表“Service Unavailable”,认为网页临时不可访问,通常网站临时关闭,带宽有限等会产生这种情况。对于网页返回503状态码,百度spider不会把这条url直接删除,同时短期内将会反复访问几次,如果网页已恢复,则正常抓取;如果继续返回503,那么这条url仍会被认为是失效链接,从库中删除。 3)403代表“Forbidden”,认为网页目前禁止访问。如果是新url,spider暂时不抓取,短期内同样会反复访问几次;如果是已收录url,不会直接删除,短期内同样反复访问几次。如果网页正常访问,则正常抓取;如果仍然禁止访问,那么这条url也会被认为是失效链接,从库中删除。 4)301代表是“Moved Permanently”,认为网页重定向至新url。当遇到站点迁移、域名更换、站点改版的情况时,我们推荐使用301返回码,同时使用站长平台网站改版工具,以减少改版对网站流量造成的损失。
其他框架
使用codeigniter,发生异常是抛出500头部。包括其他的框架都是5xx头。(原创by [email protected],转载请著名出处,欢迎交流)

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

The reason for the error is NameResolutionError(self.host,self,e)frome, which is an exception type in the urllib3 library. The reason for this error is that DNS resolution failed, that is, the host name or IP address attempted to be resolved cannot be found. This may be caused by the entered URL address being incorrect or the DNS server being temporarily unavailable. How to solve this error There may be several ways to solve this error: Check whether the entered URL address is correct and make sure it is accessible Make sure the DNS server is available, you can try using the "ping" command on the command line to test whether the DNS server is available Try accessing the website using the IP address instead of the hostname if behind a proxy

To run the ThinkPHP project, you need to: install Composer; use Composer to create the project; enter the project directory and execute php bin/console serve; visit http://localhost:8000 to view the welcome page.

ThinkPHP has multiple versions designed for different PHP versions. Major versions include 3.2, 5.0, 5.1, and 6.0, while minor versions are used to fix bugs and provide new features. The latest stable version is ThinkPHP 6.0.16. When choosing a version, consider the PHP version, feature requirements, and community support. It is recommended to use the latest stable version for best performance and support.

Differences: 1. Different definitions, url is a uniform resource locator, and html is a hypertext markup language; 2. There can be many urls in an html, but only one html page can exist in a url; 3. html refers to is a web page, and url refers to the website address.

Steps to run ThinkPHP Framework locally: Download and unzip ThinkPHP Framework to a local directory. Create a virtual host (optional) pointing to the ThinkPHP root directory. Configure database connection parameters. Start the web server. Initialize the ThinkPHP application. Access the ThinkPHP application URL and run it.

Performance comparison of Laravel and ThinkPHP frameworks: ThinkPHP generally performs better than Laravel, focusing on optimization and caching. Laravel performs well, but for complex applications, ThinkPHP may be a better fit.

"Development Suggestions: How to Use the ThinkPHP Framework to Implement Asynchronous Tasks" With the rapid development of Internet technology, Web applications have increasingly higher requirements for handling a large number of concurrent requests and complex business logic. In order to improve system performance and user experience, developers often consider using asynchronous tasks to perform some time-consuming operations, such as sending emails, processing file uploads, generating reports, etc. In the field of PHP, the ThinkPHP framework, as a popular development framework, provides some convenient ways to implement asynchronous tasks.

ThinkPHP installation steps: Prepare PHP, Composer, and MySQL environments. Create projects using Composer. Install the ThinkPHP framework and dependencies. Configure database connection. Generate application code. Launch the application and visit http://localhost:8000.
