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.

Post New Thread Reply

Register GFY Rules Calendar Mark Forums Read
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed.

 
Thread Tools
Old 04-18-2005, 03:05 PM   #1
nmcog
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");

?>
nmcog is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 04-18-2005, 03:10 PM   #2
ezey
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
ezey is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 04-18-2005, 03:11 PM   #3
Fuckin Bill
Confirmed User
 
Join Date: Feb 2003
Posts: 1,020
Or use any of the countless scripts already out there that do this.
Fuckin Bill is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 04-18-2005, 03:29 PM   #4
nmcog
Confirmed User
 
Join Date: Sep 2004
Posts: 825
Thanks for answering my question....not..
nmcog is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 04-18-2005, 03:32 PM   #5
SilverTab
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
SilverTab is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 04-18-2005, 03:39 PM   #6
nmcog
Confirmed User
 
Join Date: Sep 2004
Posts: 825
Quote:
Originally Posted by SilverTab
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
I'd do that if I knew how
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]);
nmcog is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 04-18-2005, 03:41 PM   #7
SilverTab
Confirmed User
 
Join Date: Nov 2001
Location: MTL
Posts: 5,060
Quote:
Originally Posted by nmcog
I'd do that if I knew how
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]);

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
SilverTab is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 04-18-2005, 03:43 PM   #8
pstation
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
pstation is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 04-18-2005, 03:45 PM   #9
pstation
Confirmed User
 
Join Date: Jul 2003
Location: chicago
Posts: 1,135
Quote:
Originally Posted by nmcog
I'd do that if I knew how
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]);
you might benefit from using
PHP Code:
$url mysql_result($result0); 
pstation is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 04-18-2005, 03:59 PM   #10
Alky
Confirmed User
 
Alky's Avatar
 
Join Date: Apr 2002
Location: Houston
Posts: 5,651
yea i was gonna say use mysql_result
Alky is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 04-18-2005, 04:10 PM   #11
nmcog
Confirmed User
 
Join Date: Sep 2004
Posts: 825
Thanks peeps...
nmcog is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 04-18-2005, 05:00 PM   #12
woj
<&(©¿©)&>
 
woj's Avatar
 
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
woj is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 04-19-2005, 12:24 AM   #13
zagi
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
zagi is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 04-19-2005, 12:38 AM   #14
Lane
Will code for food...
 
Join Date: Apr 2001
Location: Buckeye, AZ
Posts: 8,496
Quote:
Originally Posted by SilverTab
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
that's certainly not the 'best way'
__________________
Lane is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 04-19-2005, 12:40 AM   #15
Lane
Will code for food...
 
Join Date: Apr 2001
Location: Buckeye, AZ
Posts: 8,496
Quote:
Originally Posted by zagi
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.
you can easily use up all available connection if thats not setup properly.
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.
__________________
Lane is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 04-19-2005, 05:07 PM   #16
CamelNose
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
CamelNose is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 04-19-2005, 05:26 PM   #17
Repetitive Monkey
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
}
Repetitive Monkey is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 04-19-2005, 05:29 PM   #18
naitirps
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
naitirps is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 04-19-2005, 05:30 PM   #19
pstation
Confirmed User
 
Join Date: Jul 2003
Location: chicago
Posts: 1,135
Quote:
Originally Posted by Repetitive Monkey
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
}
it's probably better to use the set_error_handler function because otherwise your code usually becomes cluttered with the error handling
pstation is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 04-19-2005, 05:33 PM   #20
SilverTab
Confirmed User
 
Join Date: Nov 2001
Location: MTL
Posts: 5,060
Quote:
Originally Posted by Lane
that's certainly not the 'best way'

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
SilverTab is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 04-19-2005, 05:39 PM   #21
Repetitive Monkey
Confirmed User
 
Join Date: Feb 2004
Posts: 3,505
Quote:
Originally Posted by pstation
it's probably better to use the set_error_handler function because otherwise your code usually becomes cluttered with the error handling
Personal tastes. I like me a sexy script filled with tab-formatted perfection.
Repetitive Monkey is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Post New Thread Reply
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >

Bookmarks
Thread Tools



Advertising inquiries - marketing at gfy dot com

Contact Admin - Advertise - GFY Rules - Top

©2000-, AI Media Network Inc



Powered by vBulletin
Copyright © 2000- Jelsoft Enterprises Limited.