


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!

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











Laravel is a PHP framework for easy building of web applications. It provides a range of powerful features including: Installation: Install the Laravel CLI globally with Composer and create applications in the project directory. Routing: Define the relationship between the URL and the handler in routes/web.php. View: Create a view in resources/views to render the application's interface. Database Integration: Provides out-of-the-box integration with databases such as MySQL and uses migration to create and modify tables. Model and Controller: The model represents the database entity and the controller processes HTTP requests.

When developing websites using CraftCMS, you often encounter resource file caching problems, especially when you frequently update CSS and JavaScript files, old versions of files may still be cached by the browser, causing users to not see the latest changes in time. This problem not only affects the user experience, but also increases the difficulty of development and debugging. Recently, I encountered similar troubles in my project, and after some exploration, I found the plugin wiejeben/craft-laravel-mix, which perfectly solved my caching problem.

Want to learn the Laravel framework, but suffer from no resources or economic pressure? This article provides you with free learning of Laravel, teaching you how to use resources such as online platforms, documents and community forums to lay a solid foundation for your PHP development journey from getting started to master.

In the Laravel framework version selection guide for beginners, this article dives into the version differences of Laravel, designed to assist beginners in making informed choices among many versions. We will focus on the key features of each release, compare their pros and cons, and provide useful advice to help beginners choose the most suitable version of Laravel based on their skill level and project requirements. For beginners, choosing a suitable version of Laravel is crucial because it can significantly impact their learning curve and overall development experience.

Laravel provides a comprehensive Auth framework for implementing user login functions, including: Defining user models (Eloquent model), creating login forms (Blade template engine), writing login controllers (inheriting Auth\LoginController), verifying login requests (Auth::attempt) Redirecting after login is successful (redirect) considering security factors: hash passwords, anti-CSRF protection, rate limiting and security headers. In addition, the Auth framework also provides functions such as resetting passwords, registering and verifying emails. For details, please refer to the Laravel documentation: https://laravel.com/doc

Article summary: This article provides detailed step-by-step instructions to guide readers on how to easily install the Laravel framework. Laravel is a powerful PHP framework that speeds up the development process of web applications. This tutorial covers the installation process from system requirements to configuring databases and setting up routing. By following these steps, readers can quickly and efficiently lay a solid foundation for their Laravel project.

The Laravel framework has built-in methods to easily view its version number to meet the different needs of developers. This article will explore these methods, including using the Composer command line tool, accessing .env files, or obtaining version information through PHP code. These methods are essential for maintaining and managing versioning of Laravel 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.
