Question: Is it possible to use something like sessions like the ones in PHP in C++?

In PHP they're used like

```
$_SESSION['name'] = $value;

```

I really want to make the same application using C++ as PHP...requires a run-time parser.

My application written in PHP uses sessions so that i can fetch some stuff from a website(numbers) and store the value in a SESSION varible which i call last to compare it to the new value when the page is reloaded.

I'd rather have the same functionality in C++.

Seeing as this is going nowhere i am going to provide the PHP code

```
<?php
session_start();

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL,"http://dashjr.org/~luke-jr/programs/bitcoin/pool/balances.json");
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
$result=curl_exec ($ch);
curl_close ($ch);

echo 'Last BTC: '.$_SESSION['last'].'<br>';

$obj = json_decode($result,true);
echo 'Current BTC: ';
$new = (int)$obj["1Hy5h24yBYKtQ1vNGaxY5rBJSEuTiMkBkx"]["balance"]/100000000;
echo $new;

if((int)$_SESSION['last'] < $new)
{
    echo '<br><br>You earned more';
}
else
{
    echo '<br><br>You earned less';
}

$_SESSION['last'] = $obj["1Hy5h24yBYKtQ1vNGaxY5rBJSEuTiMkBkx"]["balance"]/100000000;

unset($result,$obj);

?>

```

I need to port *that* to C++.

Answer: 
The concept of a "session" as in a "PHP session" only makes sense if you are doing server-side Web development. C++ was designed to be as general-purpose as possible (whether that goal was achieved is a completely different story), so it does not natively support any concept related to any specific application. Which, in your particular case, means C++ has no native concept of a "session", of course.

Of course, *in theory*, you could do PHP-style Web development in C++, including using PHP-like sessions. But you would have to either (1) use some framework exposing PHP-like session functionality, which I doubt anyone has ever developed; or (2) implement said framework yourself, which would be *really* inconvenient. And there would no tangible advantage you could get in return for your inconvenience: The main reasons why people use C++ these days are (1) performance is too critical to use a higher-level language, and (2) compatibility with other systems written in C++ is a requirement. (1) does not apply, because, in most cases, a Web application's response time is dominated by the time it takes to transmit messages across the network, even for Web applications deployed in an Intranet. The time it takes a Web server to process a request, however complex, is often minuscule in comparison. And (2) does not apply because systems interoperating on the Web are developed following standards that ensure the technologies underlying these systems do not matter.

Most people saying they need to implement their applications in C++ are people who have already implemented said applications in their languages of choice (or their bosses' languages of choice) and found performance problems. In my experience, most software-caused performance problems arise from the fact applications are not properly designed and/or implemented with scalability in mind. For a Web application, things like minimizing the amount of server trips (each time a particular value/object/whatever has to be sent across the network in order to get a response back) are the kind of design decisions that can meaningfully affect performance.

In short: If performance problems are the reason why you want to implement this application in C++, you better analyze each part of your current PHP system, determine which one(s) are causing the performance issues, and redesign and reimplement them.
> 
> PHP...requires a run-time parser.
> 
> 
> 

Nope, install apc or any other compiled code cache, and php is only parsed once. Of course the generated bytecode is still interpreted...

On big frameworks (lots of code) parsing time can be a lot longer than actual script execution, so this cuts down the page times quite a lot.