


Hosts file configuration error causes application lag (Laravel-Sail development environment)
The following tutorial column of laravel will introduce to you the problem of application lag caused by incorrect hosts file configuration (Laravel-Sail development environment). I hope it will be helpful to friends who need it. help!
Today I pulled down the source code of a project and used the new Laravel-Sail development environment. The previous Homestead development environment is now only a backup. Everything went smoothly at first, including dependency installation, container startup, and data migration. Then I happily configured the domain name for development into the hosts file:
127.0.0.1 devocus.test
Open the browser and visit: http ://devocus.test:8016
, I thought everything was going well, but I found that the page was always loading, and it took almost 30 seconds for the complete interface to be loaded. I was puzzled. Several other projects I always use the Laravel-Sail development environment, and it almost always starts in seconds. Is this project swollen?
Then I opened the browser developer tools and found that all requests took more than 30 seconds. Did I encounter a file IO problem? But my project is placed in the Ubuntu subsystem. Internet problem? The other items are completely normal. I tried every possible solution, changing file permissions, closing ladder, deleting and re-creating the container, etc., but to no avail.
So I installed Telescope and checked the details of each request. Opening Telescope was also very slow. I waited for about a minute before the Telescope interface finally loaded. But the query results surprised me very much:
Telescope shows that each request is processed very quickly, and the data query is also very fast. I am amazed...
So we tried it on a colleague’s computer. The development environment was Laravel-Sail. Unexpectedly, the access on his computer was also very slow. This directly led our thinking to the direction of "there is a problem with the project code", so I spent I spent a whole morning carefully comparing and checking various configuration files and env files, and upgraded laravel and various dependent versions. But every time I open the application in the browser with great expectations, it still freezes and makes me doubt my life, and the log records are all normal. Then use a search engine to try to search for a solution to this problem. There are no results in Chinese or English searches. A morning passed, and I still had not solved this problem, and even a feeling of despair came to my heart.
Finally, I decided to go have lunch and relax myself first. On the way back from dinner, I thought about this question again. Various answers I searched in my head flashed one by one, and suddenly a word "flew" in front of my eyes: hosts
.
When I returned to my workstation, I turned on the computer and thought about using IP to access the application directly to see the situation, so I entered http://127.0.0.1:8016
in the browser, and the interface was opened quickly. I was probably a little confused, so I opened the hosts file and thought about changing the domain name:
# 127.0.0.1 devocus.test 127.0.0.1 ifocus-dev.test
Then opened the browser, entered http://ifocus-dev.test:8016
, and applied It was opened quickly and smoothly, and the problem was solved inexplicably.
But what’s the problem? I opened the hosts file again, checked carefully, and found that the resolution of the same domain name I had done before was lying quietly in the hosts file. When I migrated the development environment from Homestead to Laravel-Sail, I forgot to modify the hosts file:
... 192.168.10.10 devocus.test ... # 127.0.0.1 devocus.test 127.0.0.1 ifocus-dev.test
In the hosts file, what will happen if the same domain name is resolved to two IPs? I searched on the search engine and found the answer:
The computer searches for the IP in the hosts file from top to bottom. For the same domain name, take the first IP. If the first IP is blocked, it will switch to the second IP or even the Nth IP. However, this method cannot achieve the load balancing effect, but it can increase the probability of opening the website.
Since I parsed devocus.test
to two IP addresses: 192.168.10.10 and 127.0.0.1, when I open http:// in the browser devocus.test
, first access 192.168.10.10, but because my Homestead is closed, the access must fail. This process lasts for about 30 seconds, and then the system continues to search for other IPs in the hosts file, finds and The web page was opened only when accessing 127.0.0.1. Because every request has to go through this process, I feel that the system is very stuck. At this point, the problem that troubled me has been solved.
So everyone must pay more attention to these subtle problems when developing projects. Small problems can often cause huge troubles. Even a self-righteous veteran like me will fall into a deep pit. The software industry is really a practical industry that requires constant stepping on pits, digging pits, and filling pits.
But after thinking about it, if I had the Homestead environment open at the time, I might be even more troubled. #
The above is the detailed content of Hosts file configuration error causes application lag (Laravel-Sail development environment). For more information, please follow other related articles on the PHP Chinese website!

Laravel optimizes the web development process including: 1. Use the routing system to manage the URL structure; 2. Use the Blade template engine to simplify view development; 3. Handle time-consuming tasks through queues; 4. Use EloquentORM to simplify database operations; 5. Follow best practices to improve code quality and maintainability.

Laravel is a modern PHP framework that provides a powerful tool set, simplifies development processes and improves maintainability and scalability of code. 1) EloquentORM simplifies database operations; 2) Blade template engine makes front-end development intuitive; 3) Artisan command line tools improve development efficiency; 4) Performance optimization includes using EagerLoading, caching mechanism, following MVC architecture, queue processing and writing test cases.

Laravel's MVC architecture improves the structure and maintainability of the code through models, views, and controllers for separation of data logic, presentation and business processing. 1) The model processes data, 2) The view is responsible for display, 3) The controller processes user input and business logic. This architecture allows developers to focus on business logic and avoid falling into the quagmire of code.

Laravel is a PHP framework based on MVC architecture, with concise syntax, powerful command line tools, convenient data operation and flexible template engine. 1. Elegant syntax and easy-to-use API make development quick and easy to use. 2. Artisan command line tool simplifies code generation and database management. 3.EloquentORM makes data operation intuitive and simple. 4. The Blade template engine supports advanced view logic.

Laravel is suitable for building backend services because it provides elegant syntax, rich functionality and strong community support. 1) Laravel is based on the MVC architecture, simplifying the development process. 2) It contains EloquentORM, optimizes database operations. 3) Laravel's ecosystem provides tools such as Artisan, Blade and routing systems to improve development efficiency.

In this era of continuous technological advancement, mastering advanced frameworks is crucial for modern programmers. This article will help you improve your development skills by sharing little-known techniques in the Laravel framework. Known for its elegant syntax and a wide range of features, this article will dig into its powerful features and provide practical tips and tricks to help you create efficient and maintainable web applications.

Laravel and ThinkPHP are both popular PHP frameworks and have their own advantages and disadvantages in development. This article will compare the two in depth, highlighting their architecture, features, and performance differences to help developers make informed choices based on their specific project needs.

Building user login capabilities in Laravel is a crucial task and this article will provide a comprehensive overview covering every critical step from user registration to login verification. We will dive into the power of Laravel’s built-in verification capabilities and guide you through customizing and extending the login process to suit specific needs. By following these step-by-step instructions, you can create a secure and reliable login system that provides a seamless access experience for users of your Laravel application.


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

SublimeText3 Linux new version
SublimeText3 Linux latest version

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

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function