![]() |
|
||
|
|
|
||
|
|
|||
|
|
|||||||
| Notices |
| Legacy Archived Main Board Business chat and general industry chat. All participation is welcome. Dont post your fucking spam here. |

![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Stay Out Of The Box
Want to see your own Advertising Here!
Join Date: Oct 2002
Location: Lost in the ozone
Posts: 10,318
|
This might be totally stupid question, but then again, it may not.
Is there a way to create a server side variable ? What I am trying to do (and I am just starting to look at this, haven't even searched on it yet..lol) is create a counter that can be referenced by a script. The objective is to avoid having to open and close a file. Instead I want a variable that will reside in memory and will be available everytime the script is called for. I need to be able to increment and decrement the counter via script. I can do it easily enough by reading the variable in, inrementing it, writing it back. But it seems like it would be better if I could just reference a memvar if possible. Thanx in advance Geekily yours Sarettah
__________________
![]() Free Adult Webcams |
|
|
|

|
|
#2 |
|
Members
Join Date: Oct 2003
Posts: 113
|
Speaking for Apache 1.3.x, the only way you can share variables accross child processes is through shared memory (shmget() etc). To accomplish this you're going to have to write an Apache module in C. I wrote one a few years ago that used shared memory for tracking some things, if you're having trouble i can dig it out next week.
I don't see much wrong with just reading/incrementing/writing the result to a database though.. If you use an Apache module, you could have more trouble in the future if you want to quickly put your script on other servers etc. I've got a feeling Apache 2.x can better support "global variables" accross child processes, as i think it uses pthreads instead of fork()ing. I'm not sure though, you'll have to look into it
__________________
MrBenn "As if by magic, the shopkeeper appeared." |
|
|
|
|
|
#3 |
|
Stay Out Of The Box
Want to see your own Advertising Here!
Join Date: Oct 2002
Location: Lost in the ozone
Posts: 10,318
|
Thanx
![]() I think though, that it is probably not apache that I need to address, but rather php. ![]() Been thinking about it a bit, in ASP this would be accomplished with a global defined in the global .asa file. My experience says that anything I can do in ASP I can do beeter in PHP So, I am figuring that there is something I can define through the php configuration that might work ![]() I didn't want to go to a db or a file just for speeds sake. This is for the contest landing page script. I already have a test version worked out using a mysql table with just the counter in it. I think, even though it is not really noticeable, that this is a lot more overhead (all things relative) than is necessary to complete the task. The entire thing is basically start Get hitcount - if in file, open file, read var. If in mysql, open db, select from tbl hitcount ++ - increment, if file write back, close file. if db, update, close db if hitcount>5 hitcount=1 endif case hitcount=1 redirect to team1 url hitcount=2 redirect to team2 url hitcount=3 redirect to team3 url hitcount=4 redirect to team4 url hitcount=5 redirect to nicks shave script ( )endcase end
__________________
![]() Free Adult Webcams |
|
|
|
|
|
#4 | |
|
french with welsh tendancies
Join Date: Oct 2002
Posts: 2,007
|
Quote:
50k hits, even all on the same day, isnt alot to handle for apache/php/mysql
__________________
![]() LiveBucks / Privatefeeds - Giving you money since 1999 Up to 40% Commission! 25% Webmaster Referal |
|
|
|
|
|
|
#5 | |
|
Banned
Want to see your own Advertising Here!
Join Date: Oct 2002
Location: Vancouver Canada
Posts: 15,115
|
Quote:
|
|
|
|
|
|
|
#6 |
|
Stay Out Of The Box
Want to see your own Advertising Here!
Join Date: Oct 2002
Location: Lost in the ozone
Posts: 10,318
|
lolol...thought you would appreciate that Nick
![]() Well, I think I found what I need. Gonna go play with it a bit. Using Zend (right under "creating variables" in the php manual...what a weird place to find it, ya know ? )Anyway, yeah, I know I can do it with a db, thats what my test is using. But, I like eloquence And when I know I should be able to do something I have this overriding need to figure it out. Thanx Guys I'll let you know how it goes
__________________
![]() Free Adult Webcams |
|
|
|
|
|
#7 |
|
Members
Join Date: Oct 2003
Posts: 113
|
Ah, you're right about PHP.. it has functions for working with shared memory. Didn't think of that to start with as the thing i'd previously done had to be a 100% self contained module
![]() If you want to do it without Zend, then the PHP SHM functions are at http://www.php.net/shmop Edit: Remember that if your server dies, you're going to loose all of your data if it's only in memory. Might be worth at least writing it to a DB every so often as a backup.
__________________
MrBenn "As if by magic, the shopkeeper appeared." |
|
|
|
|
|
#8 |
|
Stay Out Of The Box
Want to see your own Advertising Here!
Join Date: Oct 2002
Location: Lost in the ozone
Posts: 10,318
|
Well... Not having much look with the zend version. Getting a syntax error off of the ZEND_SET_SYMBOL() function and I have tried about every different variation I can think of. And of course, the only example I find when I search is the PHP manual (which is where I grabbed the model I am using came from).
Thanx MR Benn for the shmod ref. I have it cookmarked for later investigation. But, I have wasted enough time on this. I have a working model using mysql, guess I will work that to the live version ![]() Thanx again ![]() Now, got to go work out the trade script..... Nick, was that every 3rd that you get, or every 4th ?
__________________
![]() Free Adult Webcams |
|
|
|
|
|
#9 |
|
Stay Out Of The Box
Want to see your own Advertising Here!
Join Date: Oct 2002
Location: Lost in the ozone
Posts: 10,318
|
Landing page script.
http://www.bntnews.com/contest/rotateit.php (edited version of it) //run the make table script at the beginning of contest to create count table and initialize it $hitcount=0; $db = mysql_pconnect(hostname, username, password); mysql_select_db(dbasename,$db); $sql_str="select * from contest_hit_counter"; $result=mysql_query($sql_str, $db); if (mysql_num_rows($result)===0){ echo "Didn't get the record back "; } else { $hitcount=mysql_result($result,0,"hitcount"); if ($hitcount>3){ $hitcount=1; } else { $hitcount=$hitcount+1; } $sql_str="update contest_hit_counter set hitcount=" . $hitcount ; $result=mysql_query($sql_str, $db); If ($hitcount===1){ echo "redirecting to team 1 "; echo 'header("Location: http://www.team1url.com/")'; } If ($hitcount===2){ echo "redirecting to team 2 "; echo 'header("Location: http://www.team2url.com/")'; } If ($hitcount===3){ echo "redirecting to team 3 "; echo 'header("Location: http://www.team3url.com/")'; } If ($hitcount===4){ echo "redirecting to team 4 "; echo 'header("Location: http://www.team4url.com/")'; } }
__________________
![]() Free Adult Webcams |
|
|
|
|
|
#10 |
|
Cunty
Want to see your own Advertising Here!
Join Date: Jan 2003
Posts: 10,150
|
I'm getting the feeling that someone else was in there refreshing at the same time as me because I went weird, then back to normal
Nice work Sarettah So are you adding the skim feature after everyone has seen it
__________________
Sucks to be you. |
|
|
|
|
|
#11 | |
|
Members
Join Date: Oct 2003
Posts: 113
|
Quote:
![]() With it set up how it is now, if you wanted to get nearly 100% of the traffic from it all you have to do is have a script on your server look for when a hit comes in, and as soon as it does, automatically send 3 hits of your own to cycle it round to your site again. Would just need some extra checks in there aswell to keep it in sync for when a real hit arrives in the middle of your generated hits and messes the cycle up. That kind of cheating could be made a little harder, but not impossible, by keeping a daily log of IPs, and only increment the hits on uniques. I'm sure no one in the contest would even dream of this kind of manipulation anyway.. well until now
__________________
MrBenn "As if by magic, the shopkeeper appeared." |
|
|
|
|
|
|
#12 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Cunty
Want to see your own Advertising Here!
Join Date: Jan 2003
Posts: 10,150
|
Quote:
|