Reading and writing global variables in scripts in PHP

Does PHP have global variables that can be changed by one running script and read by another?

+3
source share
8 answers

No, by design, PHP is a "nothing in common" architecture, which means that nothing happens between processes running simultaneously or between requests running one after another. There are ways to exchange data, but you must do it explicitly.

If you just want to share between two requests from the same user, sessions or cookies can be sent.

, , , - , (, memcached), , .

. .

+12

$_ SESSION, :

script1.php

<?php
session_start();
$_SESSION['myVar'] = "something";
?>

script2.php

<?php
session_start();
echo $_SESSION['myVar'];
//something
?>
+3

APC ( ).

+2

, , - $_SESSION. , , , cookie, PHP script.

, script ; , .

, $_SESSION ( cookie , - ), POST GET .

+1

php. php php. - memchached module ( , ).

+1

, , , .

0

PHP - , MySQL ( )

0

. / , webapps. . ( ), , .

, , - - - - Django (python) Rails (ruby). , , , -.

-1

Source: https://habr.com/ru/post/1717885/


All Articles