I want to define a variable in php with in a global scope. That variable should be accessible for each user, so it should not depend on the session.
I want to do something like the following: I have a php script, and that script usually takes about 5 to 15 minutes to execute, but it can take more than one hour in some special cases. This script is being run using a cron job with a 15 minutes interval. This script can also be run manually by any user.
Now it’s possible to run any number of scripts at the same time. I want to limit this number of scripts.
So, I want a variable to store the number of currently executing scripts. I don’t want to use a DB or files to store a single value.
Thanks in advance.
Writing the variables to a specific memory address and reading and writing to/from that address with information such as a count might work.
An (old) article on IPC (inter process communication) might help you
http://zez.org/article/articleview/46/
Out of interest why is it you don’t want to use files or a database?
Another solution (despite more than likely technically using files or a database) would be to force the script to use a specific session ID.
Note in the example above, the call to session_write_close() is important because the execution of the script will prevent the counter being incremented until it finishes otherwise. And then as it closes it, it needs reopening to decrement the counter.
Obviously because of the session reopening, any output from the script would need to be buffered (see http://www.php.net/ob_start) to prevent headers already sent errors