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 类:全局变量作为类中的属性 2021-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- 如何替换eregi() 2022-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
