Is it bad to include a lot of files in PHP like it is for file based Sessions?

后端 未结 7 1005
遇见更好的自我
遇见更好的自我 2021-01-04 14:25

After reading about how file based PHP sessions are not the greatest for performance, it has me thinking. Does this mean a PHP script including a lot of files is bad as wel

7条回答
  •  灰色年华
    2021-01-04 15:09

    I think everyone who fiddles with PHP comes to the point when their libraries become large, and worries come up for the performance.

    My experience is that yes, if you always load all your libraries, then this is going to eat up precious memory (Of which you are allocated only a fixed number of megabytes per process). I have had source code files weighing 300-400kb (with comments) that ate 2-3 MB per script instance. Seeing that a script gets only 16-32 MB with many shared hosts, that is a lot. Also, the processing of such huge files often comes in at up to half a second per request, which is way too much.

    So, splitting up is definitely necessary, and easy to do with Autoload and consorts. Check out my answer to this question for a few suggestions on how to split up your code wisely. There is also a link to a question about how to organize a large PHP project, which yielded great results. I'm in the process of figuring out the perfect structure myself, and not done yet. :)

提交回复
热议问题