I implemented a php-cpp extension following the documentation at [enter link description here][1].
The CPP code is just one file which has a global variable(root) of type NODE(of a linked list). There are 2 functions :
My index.php contains an input box with button to add a number. When add button is pressed the value in the add box is posted to a php file which calls the add function in the CPP extension. Another button is view which display the nodes in the list, on the same page.
What I expect:
I expect that the root should retain its value across page views. i.e. if I load my index.php and add a number to the list and then try to view the list form another page, it should give me the inserted element from the first page. This should happen from any no of pages, or browsers or machines I try to load the page from. Any addition made from any source should be visible on all pages.
What is happening:
Please suggest what should I do so that the root element always points to the same list, and that the data in the list does not get lost, across multiple pageviews.
答案 0 :(得分:0)
Most likely your php script is interpreted on server by launching one or more shot-lived php interpreter processes. Each of these processes will have it's own global variable. When process dies the content of it's global variable is lost.
If you want to retain a value of variable for extended period of time then you should save it in Data Base of some kind. There are plenty of php tools to work with SQl and NO-SQL DBs.