Jump to content

richietheg

New Members
  • Posts

    2
  • Joined

  • Last visited

richietheg's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. To be honest, yes I am just 'feeling' that the database is being queried too much. It just seems bad practice to me that the database is being queried every 10 seconds or so by each user and, while currently the particular radio station I'm working with doesn't get too many listeners, the more people who are on the player the more it's being queried (I am hoping to get it so it only refreshes the data if the player is the currently active window, but one step at a time!) - it just seems to be a waste when really all that's needed is one query per show... just the shows don't start at regular times to make this possible. I guess I'm just not wanting to piss off my host with an inordinate amount of DB queries should our listenership increase! I'm not getting any problems with this number of DB queries, but this is only working on an internal server at the moment. I can't guarantee the good-ness of the DB design or its queries, though I am currently working on the queries to streamline it somewhat (I suddenly realised that I made a schoolboy error yesterday... why the hell aren't I using a 'JOIN' in my code?! ). Thanks for your reply!
  2. I apologise, for a first post this is quite a long one... I seem to be making this more complicated than it needs to be, so am wondering if there's any hints out there that will make it not so! I'm not new to PHP, but there are probably some bits of it that I don't know as well as I probably ought... I am working on a web player for an Internet radio station with the schedule data held in a mySQL database. The player updates on the screen according to the schedule with what show is currently on air and what is up next etc. That whole part of things works. A jquery refresh script calls the PHP file that queries the database every 10 seconds or so (the old schedule data was kept in a very large PHP array which was difficult to edit unless you knew PHP, and I've kept the same basic code for displaying it even if extracting the data has changed!). This method though queries the database too much to gain the same data as before. As the data retrieved includes the time the next programme starts, it seems that I should be able to only query the database when the programme has changed. An obvious way of doing this is to write a cache file that the player page calls, and use that data unless the programme has changed. The bit I'm currently struggling to wrap my head around is how to know when to change the cache, which - as I said - given that the data retrieved contains this information seems a little odd. Say the file that gets the data from the database is 'getcache.php' and the file that contains the data is 'onair-cache.php' (because, that actually is their names!). When 'getcache.php' is called, it should check 'onair-cache' for the time of next show. If this time has passed, then it should query the database for the new information and write it to 'onair-cache.php'. However, surely a file can't be written to if it's open, so putting something like: if ($programme['end_time'] <= now) { include ('getcache.php'); } into 'onair-cache.php' wouldn't work as 'getcache.php' needs to be able to write the new information into 'onair-cache.php'. Also, what would happen if there are many users who are connected at the same time, each one will end up then querying and writing at the same time? (Btw, that code was just some pseudocode that probably won't work as it is, but would just give the idea of what's needed!) As I said right at the beginning, I seem to be making this more complicated than it needs to be, so if there's a simpler way of doing it then I'd be grateful to know! Many thanks!
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.