search
HomePHP FrameworkLaravelHosts 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:

记一次 hosts 文件配置错误导致的应用卡顿问题

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!

Statement
This article is reproduced at:learnku. If there is any infringement, please contact admin@php.cn delete
Last Laravel version: Migration TutorialLast Laravel version: Migration TutorialMay 14, 2025 am 12:17 AM

What new features and best practices does Laravel's migration system offer in the latest version? 1. Added nullableMorphs() for polymorphic relationships. 2. The after() method is introduced to specify the column order. 3. Emphasize handling of foreign key constraints to avoid orphaned records. 4. It is recommended to optimize performance, such as adding indexes appropriately. 5. Advocate the idempotence of migration and the use of descriptive names.

What is the Latest LTS Version of Laravel?What is the Latest LTS Version of Laravel?May 14, 2025 am 12:14 AM

Laravel10,releasedinFebruary2023,isthelatestLTSversion,supportedforthreeyears.ItrequiresPHP8.1 ,enhancesLaravelPennantforfeatureflags,improveserrorhandling,refinesdocumentation,andoptimizesperformance,particularlyinEloquentORM.

Stay Updated: The Newest Features in the Latest Laravel VersionStay Updated: The Newest Features in the Latest Laravel VersionMay 14, 2025 am 12:10 AM

Laravel's latest version introduces multiple new features: 1. LaravelPennant is used to manage function flags, allowing new features to be released in stages; 2. LaravelReverb simplifies the implementation of real-time functions, such as real-time comments; 3. LaravelVite accelerates the front-end construction process; 4. The new model factory system enhances the creation of test data; 5. Improves the error handling mechanism and provides more flexible error page customization options.

Implementing Soft Delete in Laravel: A Step-by-Step TutorialImplementing Soft Delete in Laravel: A Step-by-Step TutorialMay 14, 2025 am 12:02 AM

Softleteinelelavelisling -Memptry-braceChortsDevetus -TeedeecetovedinglyDeveledTeecetteecedelave

Current Laravel Version: Check the Latest Release and UpdatesCurrent Laravel Version: Check the Latest Release and UpdatesMay 14, 2025 am 12:01 AM

Laravel10.xisthecurrentversion,offeringnewfeatureslikeenumsupportinEloquentmodelsandimprovedroutemodelbindingwithenums.Theseupdatesenhancecodereadabilityandsecurity,butrequirecarefulplanningandincrementalimplementationforasuccessfulupgrade.

How to Use Laravel Migrations: A Step-by-Step TutorialHow to Use Laravel Migrations: A Step-by-Step TutorialMay 13, 2025 am 12:15 AM

LaravelmigrationsstreamlinedatabasemanagementbyallowingschemachangestobedefinedinPHPcode,whichcanbeversion-controlledandshared.Here'showtousethem:1)Createmigrationclassestodefineoperationslikecreatingormodifyingtables.2)Usethe'phpartisanmigrate'comma

Finding the Latest Laravel Version: A Quick and Easy GuideFinding the Latest Laravel Version: A Quick and Easy GuideMay 13, 2025 am 12:13 AM

To find the latest version of Laravel, you can visit the official website laravel.com and click the "Docs" button in the upper right corner, or use the Composer command "composershowlaravel/framework|grepversions". Staying updated can help improve project security and performance, but the impact on existing projects needs to be considered.

Staying Updated with Laravel: Benefits of Using the Latest VersionStaying Updated with Laravel: Benefits of Using the Latest VersionMay 13, 2025 am 12:08 AM

YoushouldupdatetothelatestLaravelversionforperformanceimprovements,enhancedsecurity,newfeatures,bettercommunitysupport,andlong-termmaintenance.1)Performance:Laravel9'sEloquentORMoptimizationsenhanceapplicationspeed.2)Security:Laravel8introducedbetter

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Article

Hot Tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!