Santosh Vaza
Santosh Vaza

Reputation: 19

global variables scope in php, are they shared

i have one big doubt, all the variables that we directly declare within php page like

<?php

$testing = "hello world";


if(isset($_GET['code'])){
    $GLOBALS['testing'] = $_GET['code'];
}

function hello(){
    echo $GLOBALS['testing'];
}
hello();


?>

are these variables shared between 2 independent requests ?, like suppose 100's of requests are executed concurrently, will these global variable values shared among them, do php create a fresh set of array for each request and maintains globals in them per request?

Upvotes: 0

Views: 43

Answers (1)

elixenide
elixenide

Reputation: 44831

No, globals are specific to a particular request. If you need persistence across requests, you need sessions or another storage mechanism, whether flat files or a database.

Upvotes: 1

Related Questions