Reading and writing global variables across scripts in PHP(在 PHP 中跨脚本读取和写入全局变量)
问题描述
PHP 是否有全局变量可以被一个正在运行的脚本修改并被另一个脚本读取?
Does PHP have global variables that can be modified by one running script and read by another?
推荐答案
不,按照设计 PHP 是一种无共享"架构,这意味着在同时运行的进程之间或在一个接一个运行的请求之间不共享任何内容.有多种方法可以共享数据,但您必须明确地进行共享.
No, by design PHP is a "share nothing" architecture, which means nothing is shared between processes running at the same time or between requests running one after another. There are ways to share data, but you have to do it explicitly.
如果您只想在来自同一用户的 2 个请求之间共享,会话或 cookie 可能是您要走的路.
If you just want to share between 2 requests from the same user, sessions or cookies might be the way to go.
如果您想在多个用户之间共享,您可能需要某种共享持久性,要么是短期缓存(例如 memcached),要么像数据库一样更健壮.
If you want to share between multiple users, you probably want some sort of shared persistence, either short term in a cache (eg. memcached) or more robust like a database.
无论哪种方式,数据实际上都在每次请求时被检索和重建.它只是在会话的情况下自动为您处理.
Either way, the data is actually being retrieved and reconstructed on each request. It's just handled automatically for you in the case of sessions.
这篇关于在 PHP 中跨脚本读取和写入全局变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 PHP 中跨脚本读取和写入全局变量


基础教程推荐
- PHP 守护进程/worker 环境 2022-01-01
- 找不到类“AppHttpControllersDB",我也无法使用新模型 2022-01-01
- 在 CakePHP 2.0 中使用 Html Helper 时未定义的变量 2021-01-01
- 如何在 XAMPP 上启用 mysqli? 2021-01-01
- phpmyadmin 错误“#1062 - 密钥 1 的重复条目‘1’" 2022-01-01
- 使用 PDO 转义列名 2021-01-01
- HTTP 与 FTP 上传 2021-01-01
- 在 yii2 中迁移时出现异常“找不到驱动程序" 2022-01-01
- 如何在 Symfony 和 Doctrine 中实现多对多和一对多? 2022-01-01
- Doctrine 2 - 在多对多关系中记录更改 2022-01-01