The Geek Forum

Main Forums => Homework Help => Topic started by: scribcake on January 14, 2009, 09:43:33 AM

Title: General question regarding CGI programming
Post by: scribcake on January 14, 2009, 09:43:33 AM
Hey guys, know I haven't posted in a while. I was pretty busy with school for the last 4 months...

I started learning PHP and PostgreSQL as one of my new years resolutions for 2009, and to facilitate in my learning, I decided to develop an actual application, rather than just write random little scripts  :-P

Basically the application is a networked sales vendor system, for the metaverse Second Life (which I have been a long time member of), that utilizes a PHP backend to keep track of sales for individual users. Allowing users to view tables of their sales, and sort them based on sale volume, vendors sold from, etc... And then export the data to excel.

Anyway, one problem that I am facing at this point is how I am going to remove vendor records from the database, when they are deleted within Second Life. There is no way for me to send requests from the server into Second Life; I can only send http requests from SL to my server.

One solution I have devised is to have a timer in my scripts that will have the vendors ping my server, updating a timestamp. I will then have CGI on my server that will run a garbage collection routine that will go through my database and flag entries which have not had the timestamp updated within a certain amount of time, and alerting the user that their vendors/servers are no longer available in world.

The problem I'm having is I don't know the first thing about CGI. I'm thinking that Perl would be good for this, but I'm not absolutely sure...

Does anyone know some good tutorials for Perl CGI programming that would allow me to have a script like this, which continuously runs in the background on my server? I tried Google but I am having difficulty finding what I'm looking for... :|
Title: Re: General question regarding CGI programming
Post by: BizB on January 14, 2009, 10:10:31 AM
You're looking for something to accept the ping from the vendors and update the time stamp in the table, right?

PERL would work well for this.  You can write a PERL script and pass parameters in the URL.  It's not exactly rocket surgery.

http://tinyurl.com/76f8co (http://tinyurl.com/76f8co)
Title: Re: General question regarding CGI programming
Post by: scribcake on January 14, 2009, 10:16:14 AM
I do all the http request handling with PHP, so updating the time stamps is not a problem. The problem is how I can have a routine running on my server that would check my database, and flag the old entries.

Again I am not really completely certain whether I am even looking in the right place for a solution... maybe the answer is with something other than CGI o.O

Edit: I just got an IM from one of my friends on skype, apparently I can run php stand alone on my server... which I was completely unaware of  :oops:.. so I guess I might just be able to use php for this. I'll have to look into it when I get home from work :-p
Title: Re: General question regarding CGI programming
Post by: BizB on January 14, 2009, 10:29:35 AM
Oh!  You should be able to schedule a process on the MySQL to do that.
Title: Re: General question regarding CGI programming
Post by: scribcake on January 14, 2009, 10:37:56 AM
Alright, I was thinking it might be possible to do something like that as well...

My friend mentioned using cron jobs though... but I think setting up a process on my MySQL server directly would be much easier, since all it really needs to do is check the table containing vendor keys for all the users for entries with a timestamp that is say more than 10 minutes old, and set a field for that entry to true.

Although I may want to implement a system of emailing the user when a vendor/server is flagged as offline, so they can know if their systems go offline in world asap. I'll probably have to do it with cron if I want to implement something like that.
Title: Re: General question regarding CGI programming
Post by: ivan on January 14, 2009, 11:00:31 AM
This does not address your question exactly, but: How many vendors are you anticipating? If it's just a handful, then the timestamp cycle will be fine, but if it's thousands it can be a costly script to run. Why not just send a daily list of active vendors from SL to your server?
Title: Re: General question regarding CGI programming
Post by: scribcake on January 14, 2009, 11:14:27 AM
That is actually a good point ivan...

While this is somewhat just a personal project as a way of learning php, I do plan to market it if it works as intended. So there could be hundreds to thousands of vendors. So I can see your point...

But I am having trouble thinking of a way sending a daily list to the server would resolve the problem without some sort of scheduled script to check the database...
Title: Re: General question regarding CGI programming
Post by: ivan on January 14, 2009, 02:50:38 PM
Well, since I know some SQL, I would find a way to schedule a mySQL script, as BizB suggested.

Assuming you have a vendor table, I would set up an Active Vendors table that gets filled by a feed from SL.

Your SQL script would find vendors in your vendor table that are missing in the Active Vendors table, mark them as deleted, then truncate Active Vendors for the next run.

I don't know what the limitations of mySQL are, but with regular MSSQL you can do practically anything.