![]() |
![]() |
![]() |
||||
Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact us. |
![]() ![]() |
|
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed. |
|
Thread Tools |
![]() |
#1 |
Confirmed User
Join Date: Sep 2004
Posts: 825
|
PHP Question
I've done a sponsor click tracking script with a MySQL database, it works so far, but is this the efficient code (least strain on the server, etc.)
It will be called up 10,000/day. go.php Code:
<? $username = 'username'; $password = 'password'; $database = 'database'; $hostname = 'localhost'; mysql_connect($hostname, $username, $password); mysql_select_db($database); $domain = $_GET['site']; mysql_query("UPDATE Sponsors SET Clicks=Clicks+1 WHERE Domain='$domain'"); $result = mysql_query("SELECT URL FROM Sponsors WHERE Domain='$domain'") or die ("Invalid entry!"); $output = mysql_fetch_row($result); $url = ($output[0]); mysql_close(); header("Location: $url"); ?> |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#2 |
Registered User
Join Date: Apr 2002
Posts: 96
|
if you just want to count clicks to sponsors i would use plain txt files instead of sql
![]()
__________________
ICQ: 410318 |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#3 |
Confirmed User
Join Date: Feb 2003
Posts: 1,020
|
Or use any of the countless scripts already out there that do this.
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#4 |
Confirmed User
Join Date: Sep 2004
Posts: 825
|
Thanks for answering my question....not..
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#5 |
Confirmed User
Join Date: Nov 2001
Location: MTL
Posts: 5,060
|
Not bad...the server can handle it......best way to do it is to store everything in a txt file and run a cron tab every 3-4 minutes that takes it, update the DB, and clean the txt file....so you reduce the # of queries/day drastically
__________________
mmm my sig was too big... no more cool animation ![]() but hey still! need php? ICQ: 94586959 |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#6 | |
Confirmed User
Join Date: Sep 2004
Posts: 825
|
Quote:
![]() I ripped out code from TGP Rotator and edited it... This part of the code I think is slightly wrong and could be done another way? Code:
$result = mysql_query("SELECT URL FROM Sponsors WHERE Domain='$domain'") or die ("Invalid entry!"); $output = mysql_fetch_row($result); $url = ($output[0]); |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#7 | |
Confirmed User
Join Date: Nov 2001
Location: MTL
Posts: 5,060
|
Quote:
well the code itself is good! but it depends...not sure what you want to do ;)
__________________
mmm my sig was too big... no more cool animation ![]() but hey still! need php? ICQ: 94586959 |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#8 |
Confirmed User
Join Date: Jul 2003
Location: chicago
Posts: 1,135
|
As long as you're using an index on the Domain field, all should be good
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#9 | |
Confirmed User
Join Date: Jul 2003
Location: chicago
Posts: 1,135
|
Quote:
PHP Code:
|
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#10 |
Confirmed User
Join Date: Apr 2002
Location: Houston
Posts: 5,651
|
yea i was gonna say use mysql_result
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#11 |
Confirmed User
Join Date: Sep 2004
Posts: 825
|
Thanks peeps...
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#12 |
<&(©¿©)&>
Industry Role:
Join Date: Jul 2002
Location: Chicago
Posts: 47,882
|
at 10k hits per day, you shouldn't have any problems with that script...
__________________
Custom Software Development, email: woj#at#wojfun#.#com to discuss details or skype: wojl2000 or gchat: wojfun or telegram: wojl2000 Affiliate program tools: Hosted Galleries Manager Banner Manager Video Manager ![]() Wordpress Affiliate Plugin Pic/Movie of the Day Fansign Generator Zip Manager |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#13 |
Confirmed User
Join Date: Jan 2004
Posts: 1,238
|
change mysql_connect to mysql_pconnect -- this will enable persistent connections and allow you to bypass the setup/teardown for mysql connections increasing the speed of your script significantly.
__________________
Managed US/NL Hosting [ [Reality Check Network ] Dell XEON Servers + 1/2/3 TB Packages ICQ: 4-930-562 |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#14 | |
Will code for food...
Join Date: Apr 2001
Location: Buckeye, AZ
Posts: 8,496
|
Quote:
__________________
![]() |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#15 | |
Will code for food...
Join Date: Apr 2001
Location: Buckeye, AZ
Posts: 8,496
|
Quote:
and the speed increase is not significant at all, the bottleneck is the write operations for each hit. you can still do a million hits a day with a beefy server though. so why fix it if it aint broken. if you want real optimization for high load, u're gonna need a few more lines of code than that.
__________________
![]() |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#16 |
Registered User
Join Date: Feb 2005
Posts: 3
|
10,000 transactions per day should not be a problem for MySql.
1) Make sure you put an index on the key search field. This will increase performance more than anything else. 2) Performance can be enhance by tuning server parameters See Docs . 3) The new release of MySql 5.0 has a performance feature called "Stored Procedures". This lets you pre-compile your MySql query so MySql does not have to compile the same query over and over again. As this is my first posting of GFY, please forgive any glaring errors. Kind regards, Bill |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#17 |
Confirmed User
Join Date: Feb 2004
Posts: 3,505
|
With the suggestions already added in regards to persistent connections and the setting of an index on the "domain" column, I don't have anything to add but a note of the glaring lack of error handling in your script. It shouldn't be a problem for the diligent webmaster, but there is something about the missing safety procedures that irks me any way.
I always use if(@){ // continue }else{ // handle as appropriate, whether by continued operation under alternative means or by throwing a custom error } |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#18 |
Confirmed User
Join Date: May 2004
Location: ...
Posts: 761
|
on one of my bigger boxes, I do about 556.23 sql queries per minute right now... no problems.
__________________
Programmer ICQ 44035273 | AIM spritwork | Email spritian at spritian dot com |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#19 | |
Confirmed User
Join Date: Jul 2003
Location: chicago
Posts: 1,135
|
Quote:
|
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#20 | |
Confirmed User
Join Date: Nov 2001
Location: MTL
Posts: 5,060
|
Quote:
ok...maybe not the "best" way.... but still works pretty good and you can process a lot of info with very few queries...and you don't lose any info at all if you do it right....
__________________
mmm my sig was too big... no more cool animation ![]() but hey still! need php? ICQ: 94586959 |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#21 | |
Confirmed User
Join Date: Feb 2004
Posts: 3,505
|
Quote:
|
|
![]() |
![]() ![]() ![]() ![]() ![]() |