Ok.
The issue is that a session is a unique "conversation" between the web server and the client.
When first script gets loaded into browser, a session is created, and assigned a name, for example "xxx".
When the second script gets "curled", it is being curled by the web server. (Since those are both yur scripts, the client and server in that "conversation" are one and the same, but this is just a side note, irrelevant to the process).
So your webserver's client is your browser for script1, but it is the webserver itself for script2. Because of that, another session is created and called "yyy".
The script3 is once again going to the browser, and therefore uses session "xxx" as well.
So when first script and third script are working with variable "aaa", they are working with the following object stored on the server:
allsessions["xxx"]["aaa"]
but when the second script gets executed, it is working with
allsessions["yyy"]["aaa"]
a little closer to the technical implementation:
if your browser's IP address (well, machine it's on) is 100.100.100.100, and your webserver's is 200.200.200.200, then
when scripts 1 or 3 do
$aaa = 3; it is equivalent (not php equivalent, but rather actual storage) to
servers[serverinstance]->allsessions["100.100.100.100"]["aaa"] = 3;
but for script 2 it is
servers[serverinstance]->allsessions["200.200.200.200"]["aaa"] = 3;
So either a) have script 2 write stuff to db or b) have script 2 return value (such as trans id), or c) do NOT curl your own pages -- there are other easier and faster-executing ways to achieve what you need.