search
HomeBackend DevelopmentPHP Tutoriallinux 服务器负载很高,缘由貌似是 php进程过多,而且一直保持 400多

linux 服务器负载很高,缘由貌似是 php进程过多,而且一直保持 400多linux 服务器负载很高,缘由貌似是 php进程过多,而且一直保持 400多 ,有图所示,php-cgi 进程数一直是不降的,没有用户访问网站也是这么多,每个进程大概占用内存150-200M左右,16G内存有时候会阻塞。求大牛帮忙。,负载有时候会达到顶峰,前无古人后无来者,120 负载,cpu 跑满。求教

回复内容:

linux 服务器负载很高,缘由貌似是 php进程过多,而且一直保持 400多linux 服务器负载很高,缘由貌似是 php进程过多,而且一直保持 400多 ,有图所示,php-cgi 进程数一直是不降的,没有用户访问网站也是这么多,每个进程大概占用内存150-200M左右,16G内存有时候会阻塞。求大牛帮忙。,负载有时候会达到顶峰,前无古人后无来者,120 负载,cpu 跑满。求教

可以考虑用fastcgi.
http://php.net/manual/en/install.fpm....

这么多的进程数load值很高也是可以预见的,建议还是查下PHP执行过程中的性能瓶颈究竟在哪。

mod_php是和apache同步执行的, 如果fastcgi的话, 服务器(一般nginx)和php之间是异步关系, 在某些情况下可以无需那么多php进程

打个比方, 如果一个用户用龟速上传一个文件, 那么apache和apache里面的那个php就在等待这个用户上传完成, 所以系统里面就需要更多的apache进程来应对并发

如果异步执行, 那么nginx在处理用户的上传, 一旦用户上传文件完成, 传给php处理只是一瞬间的事情.

当然有时候fastcgi也不一定能解决问题, 比如php在等待一个sql查询, 这个查询花了5秒, 那么5秒之内有新用户来访, 这个php就不能出门欢迎, 所以必须新开一个php进程

所以查一查你的php执行要花多久, 再看一看自己的访问量, 综合的去找原因并想办法解决吧

每个php进程都是很费内存的,建议根据服务器配置做适当调整,修改fastcgi配置文件或php-fpm配置文件,一般100个内对于大部分场景就够用了,再多就要考虑做任务调度或者消息队列处理了

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
What is the difference between unset() and session_destroy()?What is the difference between unset() and session_destroy()?May 04, 2025 am 12:19 AM

Thedifferencebetweenunset()andsession_destroy()isthatunset()clearsspecificsessionvariableswhilekeepingthesessionactive,whereassession_destroy()terminatestheentiresession.1)Useunset()toremovespecificsessionvariableswithoutaffectingthesession'soveralls

What is sticky sessions (session affinity) in the context of load balancing?What is sticky sessions (session affinity) in the context of load balancing?May 04, 2025 am 12:16 AM

Stickysessionsensureuserrequestsareroutedtothesameserverforsessiondataconsistency.1)SessionIdentificationassignsuserstoserversusingcookiesorURLmodifications.2)ConsistentRoutingdirectssubsequentrequeststothesameserver.3)LoadBalancingdistributesnewuser

What are the different session save handlers available in PHP?What are the different session save handlers available in PHP?May 04, 2025 am 12:14 AM

PHPoffersvarioussessionsavehandlers:1)Files:Default,simplebutmaybottleneckonhigh-trafficsites.2)Memcached:High-performance,idealforspeed-criticalapplications.3)Redis:SimilartoMemcached,withaddedpersistence.4)Databases:Offerscontrol,usefulforintegrati

What is a session in PHP, and why are they used?What is a session in PHP, and why are they used?May 04, 2025 am 12:12 AM

Session in PHP is a mechanism for saving user data on the server side to maintain state between multiple requests. Specifically, 1) the session is started by the session_start() function, and data is stored and read through the $_SESSION super global array; 2) the session data is stored in the server's temporary files by default, but can be optimized through database or memory storage; 3) the session can be used to realize user login status tracking and shopping cart management functions; 4) Pay attention to the secure transmission and performance optimization of the session to ensure the security and efficiency of the application.

Explain the lifecycle of a PHP session.Explain the lifecycle of a PHP session.May 04, 2025 am 12:04 AM

PHPsessionsstartwithsession_start(),whichgeneratesauniqueIDandcreatesaserverfile;theypersistacrossrequestsandcanbemanuallyendedwithsession_destroy().1)Sessionsbeginwhensession_start()iscalled,creatingauniqueIDandserverfile.2)Theycontinueasdataisloade

What is the difference between absolute and idle session timeouts?What is the difference between absolute and idle session timeouts?May 03, 2025 am 12:21 AM

Absolute session timeout starts at the time of session creation, while an idle session timeout starts at the time of user's no operation. Absolute session timeout is suitable for scenarios where strict control of the session life cycle is required, such as financial applications; idle session timeout is suitable for applications that want users to keep their session active for a long time, such as social media.

What steps would you take if sessions aren't working on your server?What steps would you take if sessions aren't working on your server?May 03, 2025 am 12:19 AM

The server session failure can be solved through the following steps: 1. Check the server configuration to ensure that the session is set correctly. 2. Verify client cookies, confirm that the browser supports it and send it correctly. 3. Check session storage services, such as Redis, to ensure that they are running normally. 4. Review the application code to ensure the correct session logic. Through these steps, conversation problems can be effectively diagnosed and repaired and user experience can be improved.

What is the significance of the session_start() function?What is the significance of the session_start() function?May 03, 2025 am 12:18 AM

session_start()iscrucialinPHPformanagingusersessions.1)Itinitiatesanewsessionifnoneexists,2)resumesanexistingsession,and3)setsasessioncookieforcontinuityacrossrequests,enablingapplicationslikeuserauthenticationandpersonalizedcontent.

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 Tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools