Laravel 9中执行php artisan serve命令一段时间后报错求助
Hey there! I totally get how frustrating it is when your Laravel 9 dev server crashes after running for a bit—especially when you’re just getting your feet wet with the framework. Since you mentioned you have a screenshot but haven’t shared the exact error yet, let’s go through some common fixes that usually resolve this kind of issue with php artisan serve:
Boost PHP’s execution time limit
A lot of times, the server times out because PHP’s default execution window is too short. You can tweak this easily:- Add or update this line in your project’s root
.envfile:PHP_MAX_EXECUTION_TIME=300 - Or find the
max_execution_timesetting in yourphp.inifile, set it to 300 (that’s 5 minutes) or higher, then restart your terminal/PHP service.
- Add or update this line in your project’s root
Swap to a more stable local server
Laravel’s built-inservecommand is lightweight, but it’s not the most reliable for long runs. Try these alternatives:- Use
php -S localhost:8000 -t public/in your terminal—it works similarly but often has better stability. - If you’re on Mac, give Laravel Valet a shot; for cross-platform, Laravel Homestead is a solid choice too.
- Use
Check for resource leaks or high memory usage
Open Task Manager (Windows) or Activity Monitor (Mac) while the server’s running. If the PHP process’s memory usage keeps climbing, you might have a loop that’s not terminating, unoptimized database queries, or a buggy third-party package. Close any unnecessary apps/terminal tabs to free up resources, then restart the server.Clear Laravel’s cached files
Corrupted cache can cause all kinds of weird crashes. Run these commands to wipe it clean:php artisan cache:clear php artisan config:clear php artisan route:clear php artisan view:clearRestart the server after running these, and see if the issue goes away.
Verify your PHP version & update dependencies
Make sure you’re running PHP 8.0.2 or higher (that’s the minimum for Laravel 9)—check withphp -vin your terminal. Also, runcomposer updateto refresh your project’s dependencies; sometimes a buggy package is the culprit.
If you can share the exact error message from your screenshot later, we can narrow this down even more!
内容的提问来源于stack exchange,提问作者Ahil Khan

