Baez Posted April 23, 2010 Share Posted April 23, 2010 I'm trying to figure out if there's a way to set a global variable that will be available to all users on one page without accessing a database. Example: 1. I create a variable called $num_users. 2. User #1 comes to the page and $num_users is then set to 1. 3. User #2 then comes to the page and $num_users is now set to 2 for both User #1 (after a page refresh obviously) and User #2. Can global variables or any other method do this? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/199451-global-variablevalue-for-multiple-visitors/ Share on other sites More sharing options...
xenophobia Posted April 23, 2010 Share Posted April 23, 2010 Two things, you need a space for you to persist your data, the number count on how many people visit this page. If you don't wished to use database, you can use a text file. Check out php's file functions. Second thing is the increment of the number, make sure you use cookie or session or other method to keep track that this user are only allowed to increase the number by 1 in the text file for first time only. There are no such variable in php can persist your value and share with other client. Quote Link to comment https://forums.phpfreaks.com/topic/199451-global-variablevalue-for-multiple-visitors/#findComment-1046831 Share on other sites More sharing options...
Baez Posted April 23, 2010 Author Share Posted April 23, 2010 Thanks for the reply. It's not that I don't know how to use databases. It's more the fact that the SQL server is working hard enough already and this will really push it. But I guess it's the only option if there's no other way to do it. Thanks again. Quote Link to comment https://forums.phpfreaks.com/topic/199451-global-variablevalue-for-multiple-visitors/#findComment-1046833 Share on other sites More sharing options...
oni-kun Posted April 23, 2010 Share Posted April 23, 2010 Thanks for the reply. It's not that I don't know how to use databases. It's more the fact that the SQL server is working hard enough already and this will really push it. But I guess it's the only option if there's no other way to do it. Thanks again. From your statement I assume you're fairly new to database based programming, I doubt you're pushing it to its 1/1000th load limit per page load, especially on such an incredibly simple increment on a row. Quote Link to comment https://forums.phpfreaks.com/topic/199451-global-variablevalue-for-multiple-visitors/#findComment-1046838 Share on other sites More sharing options...
Baez Posted April 23, 2010 Author Share Posted April 23, 2010 No I'm not new at all. That was simply an example. The table will be holding the number of users as well as up to 17 usernames. At any given time anywhere from 100-250 of these rows are being created, updated or deleted. While those rows are being updated another table will be read from to retrieve additional information. How taxing do you think that description would be? I'm not sure how to really estimate it. The server running it is decent but not overly powerful. Quote Link to comment https://forums.phpfreaks.com/topic/199451-global-variablevalue-for-multiple-visitors/#findComment-1046842 Share on other sites More sharing options...
oni-kun Posted April 23, 2010 Share Posted April 23, 2010 If you're going to be using an alternative with fopen (Using the w+ flag) You can easily iterate the number (Or log something useful to handle expireys) and display it with the complementing functions. But if you're wanting to compare perf. aspects on the writes, They are negligablly similar. A file read/write and a compiled program will handle it in a negligable speed, but if you're wanting to save resources (Assuming your queries were actually too taxing) by any means fopen would be an suitable option. I'm just not sure why you're wanting a "global" persistance of something alternate to what you have already. Quote Link to comment https://forums.phpfreaks.com/topic/199451-global-variablevalue-for-multiple-visitors/#findComment-1046846 Share on other sites More sharing options...
Baez Posted April 23, 2010 Author Share Posted April 23, 2010 Hmm I might take that route then. Thanks oni. It's more the fact that the server has ample memory and not as much processing power. So I'm trying to keep running processes to a minimum while making the most use of memory. Hence why I thought of using global variables to store everything and only using the processor to set the values from already existing $_SESSION values. Quote Link to comment https://forums.phpfreaks.com/topic/199451-global-variablevalue-for-multiple-visitors/#findComment-1046848 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.