PHP能不能把库一次加载永久使用
比如一个库, 几乎所以页面都有调用它, 有没有一种方式, 不用在每个页面都require它, 前提是这是一个函数库, 实际上每次加载都不执行代码.
------解决方案--------------------
引用文件就是自上自下始终继承的原则。假如a是你的全局文件。那么b引用了a,c引用b的时候,同时也就引用了a。e如果没有引用b就需要自己引用a。
要实现你说的方式,有三种方法:
1 把系统设计成单入口,入口处每次都加载一个全局文件,把你的全局文件让入口文件引用就成了。你可以参考mvc框架的设计方式。
入口文件 -> bootstrap -> front_controller -> router mapping -> controller a
-> controller b
-> controller c
在bootstrap中引用你的全局文件。
2 实现autoload,这样当你实例一个当前不存在的class时,它会自动去加载那个文件。
3 把你的库写成php扩展,php的扩展在php进程启动时就会自动加载并一直在进程中存在。
------解决方案--------------------
补充楼上
4.php.ini 自动加载文件,请参考 auto_prepend_file, auto_append_file ,注意session等等全局的问题
5.web服务器自动加载,参考服务器文档
6.系统自动加载,参考系统文档
------解决方案--------------------
如果你能安装成功 apc 扩展,那么他会缓存一些代码在内存中,而不必每次多文件
原来有个 eAccelerator 扩展,效果也不错,但是 php5.3 以后就不能用了
至于 apc 扩展,由于始终都没有加载成功。所以不知道是否像他说的那么管用
------解决方案--------------------
嗯 5.x后开始用 apc了.可以,感觉没有eAccelerator那么明显 不过可能是心理作用吧。
------解决方案--------------------
看到这个标题 我想了很久,对这个我不懂
------解决方案--------------------
遍历项目文件,将文件路径存储在一个文件里面,并且序列化,设置一个过期时间,每次直接从序列化的文件当中去读取,可以参考php的自动加载文件函数spl_autoload_register() 。
------解决方案--------------------
就是楼上们说的APC
------解决方案--------------------

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python are both high-level programming languages that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver Mac version
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version
Useful JavaScript development tools