buttongugl.blogg.se

Php free memory
Php free memory








php free memory

If you want to learn more about Laravel's queue system, make sure to check Laravel Queues in Action! I've put everything I know about the queue system in an eBook format along with several real-life uses cases. Occasionally restarting your workers is a very efficient strategy for dealing with memory leaks. When using Laravel Horizon, you can restart the Horizon process using a CRON job or you can configure maxJobs and maxTime in your Horizon supervisor configurations: 'environments' => [ This method can be useful if you know this specific type of job could be memory consuming and you want to make sure the worker restarts after processing it to free any reserved resources. The worker will not exit while in the middle of processing a job.įinally, you may signal the worker to exit from within a job handle method: public function handle() All associated result memory is automatically freed at the end of the scripts execution. mysqlfreeresult () only needs to be called if you are concerned about how much memory is being used for queries that return large result sets. After processing each job, the worker will check if it exceeded max-jobs or max-time and then decide between exiting or picking up more jobs. mysqlfreeresult () will free all memory associated with the result identifier result. This worker will automatically exit after processing 1000 jobs or after running for an hour. If you don't want to use a CRON task, you can use the -max-jobs and -max-time options to limit the number of jobs the worker may process or the time it should stay up: php artisan queue:work -max-jobs=1000 -max-time=3600 Workers will receive that signal and exit after finishing any job in hand. Now uncomment the unset (data) at line 7 and re-run the script, it should succeed this time, with constant memory usage. To do this, you can configure a CRON job to run every hour and call the queue:restart command: 0 * * * * forge php /home/forge//artisan queue:restartĪdding this to your /etc/crontab file will run queue:restart every hour. The unset () call tells PHP to free up the memory we know we do not need anymore, to reduce the peak memory usage. With a process manager like Supervisor in place, you can restart your workers every hour to clean the memory knowing that Supervisor will start them back for you automatically. The solution is easy though, restart the workers more often. Over time, some references will pile up in the server memory that won't be detected by PHP and will cause the server to crash at some point. With that being said, avoiding memory leaks can still be a bit challenging. I've seen how powerful Laravel workers are with crunching a very large number of jobs on different server capacities and doing the job pretty well. The job of our workers here is running a Laravel application-PHP application-and get it to process background jobs.

php free memory

Based on my experience working on large scale projects that utilize hundreds of workers, I'm on the side of the debate that believes PHP is very efficient for getting the right job done. There has been a debate-for a long time-on whether or not PHP is a good choice for long-running processes.










Php free memory