473,395 Members | 1,696 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

opening a page with the sole purpose of running an sql statement

Hi Folk

I am running a site (A) that has a US mirror (B). This means that all
the data from A is copied daily to B.

On the site, I keep some statistics of the pages people visit, tracking
them with a session and noting their searches, etc... for statistical
purposes.

The problem I have is that if someone visits site B then at the end of
the day, their statistical data is going to be overriden by the update
from A.

To counter this, I envisaged a system where the stats dont just run an
sql statement to update my MySql database, but instead, the statements
"include" a URL on A that runs the statement.

For example:

---
Old procedure:
function add_user_page() {
mysql_query("INSERT INTO USER (PAGEID, USERID) VALUES (1,2);");
}

---
New procedure:
function add_user_page() {
if(site B) {

include_once("http://A.com/runstats.php?function=add_user_pageB&table=USER&V1 =8&V2=9");
}
mysql_query("INSERT INTO USER (PAGEID, USERID) VALUES (8,9);");
}

---
I would then create a file runstats.php with the following code:

<?php
call_user_function($_GET["function"], $_GET);
function add_user_pageB ($name, $v1, $v2) {
mysql_query("INSERT INTO USER (PAGEID, USERID) VALUES
('.$v1.','.$v2.');");
}
?>

This is obviously super simplified and not tested.

The questions I have are

1. is this a good method?
2. can I / should I use "include_once" or is there a better way to run
(call) the runstats.php page?

NOTE: my ISP does not allow me to connect directly from B to the
database on A.

Thanks in advance for any comments

Nicolaas

Oct 9 '06 #1
3 1448
If replication, or a federated table (MySQL), or a remote mysql
connection isn't possible, the remote URL would work. Another option
would be to use a tracking image (1x1 transparent gif) that pointed to
server A. A would then have access to the page being viewed through
HTTP_REFERER. This method allows keep-alive to be used.

For collecting site/page stats, you might be interested in Google
Analytics (google.com/analytics) which is free, or a service like
DeepMetrix.

Depending on the app, you might take a performance hit if you open a
remote URL with each request. To optimize this, you could continue
storing the stats locally on B (say in some new tables that don't get
overwritten), and then occasionally post a dump of those tables to
server A using cURL. Batching the updates instead of sending each
insertion.

As a basic precaution, you would probably want to check the remote IP
($_SERVER['REMOTE_ADDR']) before evaluating any code. There are
additional measures you could take security-wise.

On Oct 8, 8:39 pm, "windandwaves" <nfranc...@gmail.comwrote:
Hi Folk

I am running a site (A) that has a US mirror (B). This means that all
the data from A is copied daily to B.

On the site, I keep some statistics of the pages people visit, tracking
them with a session and noting their searches, etc... for statistical
purposes.

The problem I have is that if someone visits site B then at the end of
the day, their statistical data is going to be overriden by the update
from A.

To counter this, I envisaged a system where the stats dont just run an
sql statement to update my MySql database, but instead, the statements
"include" a URL on A that runs the statement.

For example:

---
Old procedure:
function add_user_page() {
mysql_query("INSERT INTO USER (PAGEID, USERID) VALUES (1,2);");

}---
New procedure:
function add_user_page() {
if(site B) {

include_once("http://A.com/runstats.php?function=add_user_pageB&table=USER&V1 =8&V2=9");
}
mysql_query("INSERT INTO USER (PAGEID, USERID) VALUES (8,9);");

}---
I would then create a file runstats.php with the following code:

<?php
call_user_function($_GET["function"], $_GET);
function add_user_pageB ($name, $v1, $v2) {
mysql_query("INSERT INTO USER (PAGEID, USERID) VALUES
('.$v1.','.$v2.');");}?>

This is obviously super simplified and not tested.

The questions I have are

1. is this a good method?
2. can I / should I use "include_once" or is there a better way to run
(call) the runstats.php page?

NOTE: my ISP does not allow me to connect directly from B to the
database on A.

Thanks in advance for any comments

Nicolaas
Oct 9 '06 #2
Following on from windandwaves's message. . .
>Hi Folk

I am running a site (A) that has a US mirror (B). This means that all
the data from A is copied daily to B.

On the site, I keep some statistics of the pages people visit, tracking
them with a session and noting their searches, etc... for statistical
purposes.
The 'statistical purposes' bit is the clue.

You don't need real-time data reporting. That's a relief because what
happens when site A is down for maintenance and site B is on-line?

Try something like:
PrintToStatsLog(UserId,PageId,GetSiteId());
where the log would be local to each system.
This could be in raw form 4,5,B...6,7,A etc or ready to run SQL
(printf-ing instead of doing a live query.)

You can now read these in when it's convenient.

Putting things in log files gives is an opportunity to think more about
your data eg
* perhaps weed page-backs (Systems view: It's not a new visit)
* perhaps identify page-back (User view : No that's not what I wanted)
* perhaps identify page-backs (Returned to page may be one of the more
useful ones)
* perhaps measure how long it takes people to find what they're looking
for.

I'd put a timestamp on as well.

I'd also make sure any search terms were sanitized before letting them
anywhere near a database.

--
PETER FOX Not the same since the e-commerce business came to a .
pe******@eminent.demon.co.uk.not.this.bit.no.html
2 Tees Close, Witham, Essex.
Gravity beer in Essex <http://www.eminent.demon.co.uk>
Oct 9 '06 #3
Thank you both for all your help! I need some time to work with
this... Thanks a million again! It cleared up a lot for me.

Nicolaas

Oct 12 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: benny | last post by:
Hi, I have a web pageA, that include the javascript, to do some onload event so that it would load another web pageB to perform some onload action. Could I able to load the pageB without...
2
by: Christopher Ambler | last post by:
I'm wondering if there's a solution here - I have an ASPX page with a sole purpose of scaling an image. The ASPX page contains a single line with the codebehind tag, and the .cs file contains...
2
by: moondaddy | last post by:
I have a page that I'm making for the sole purpose of printing and this page makes 1.5 printed pages. Is there a way to force a print page break at a specific place so when the user prints the...
3
by: mnet123 | last post by:
I am using "Server.Transfer()" to send data to an ASP.NET page that's sole purpose is to display messages. I am using "Server.Transfer since I can set the contents of the message I want to display...
7
by: Martien van Wanrooij | last post by:
I have been faced a couple of times with the situation that I wanted to write a script and was worried about a too frequent opening and closing mysql connections. To give some examples: 1)I...
12
by: =?Utf-8?B?RnJlZU5FYXN5?= | last post by:
Hello, the scenario: There's an ASPX page which shows some text and has three buttons at the bottom: Save, Print and Close. Print and close is done by javascript. But how can I save the page...
0
by: Joseph I. Ceasar | last post by:
In an earlier post, someone asked about how to save a page on the client programmatically. I also had to solve this problem and did use Steven's approach. It worked great! Now here is an...
0
by: Joseph I. Ceasar | last post by:
In an earlier post, someone asked about how to save a page on the client programmatically. I also had to solve this problem and did use Steven's approach. It worked great! Now here is an...
3
by: Andrew Poulos | last post by:
There's a HTA application that's running on a local computer (not from a URL) and the user can open a new HTML window by clicking a button The first time the user clicks the button the window...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.