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 php.net/ob_start ) to prevent headers already sent errors.
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 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.
= $maximum ) { die( "too many processes running" ); } else { $_SESSION'count'++; } } session_write_close(); // simulate running something sleep(10); session_id(md5('myscript')); session_start(); $_SESSION'count'--; session_write_close(); echo "executed";? > 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 php.net/ob_start) to prevent headers already sent errors.
1 Shared session is a nice trick (of course, the session handler will eventually use files or databases, but I presume the OP won't mind). – Álvaro G. Vicario Aug 18 at 11:03 Thanks Ben.
This is the only solution for my problem I think... thanks again... – Aatif Farooq Aug 20 at 5:07 This is a neat trick, but could be dangerous as you could mangle the user's session or send out cookies referring to the "global" session. PHP sessions are just saved to a file (with the default set up) and are an overly complicated solution if all you want to do is save an integer's state. – Cixate Sep 7 at 14:08.
Check if limit is reached when user access script, add him to DB when user exists (or script ends), remove him from DB there's no way to save this somewhere else for everyone without file nor DB.
I don't want to use DB or files to store a single value. " :) – k102 Aug 18 at 10:23 1 in this case the answer is that it's not possible – wonk0 Aug 18 at 10:24 2 @k102: it's just not possible... – genesis Aug 18 at 10:25 I know that it's not possible. I just think it can be the only answer – k102 Aug 18 at 10:33 It's worth mentioning that scripts can crash, so sooner or later this information would need to be validated anyway.
– Álvaro G. Vicario Aug 18 at 10:34.
Your preconditions are pretty restrictive. Memory is not (or not normally) shared between scripts and we cannot use files or databases: that virtually leaves no common space available to share information, so you have to calculate the information every time. Your best option is probably to inspect the running processes, identify which ones belong to your script and count them.
Your mention to cron suggests Unix, which makes things easier. The POSIX extension probably allows to control process execution to this degree and, as last resource, you can always run the ps command from PHP.
It can also be the solution of the problem. But I like the way that "Ben Swinburne" used to store the value in the session. Thanks for your answer – Aatif Farooq Aug 20 at 5:15.
Without DB or files this isn't possible as far as I am aware of. Instead, if you have access to the server (root access) you could check with the ps command (if running a linux OS) if the script is already running and if so, you could see how much instances of it.
It can also be the solution of the problem. Actually, I was thinking to do something like this. But I like the way that "Ben Swinburne" used to store the value.
Thanks for your answer – Aatif Farooq Aug 20 at 5:14.
It's not a good idea to use $_ENV unless you are specifying an environmental variable. Echo '$foo in global scope: ' . Echo '$foo in current scope: ' .
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.