In the weekend, I worked to improve the BOINC Tasks section of my website:
Instead of manually updating this page, I’ve updated the PHP files in charge of retrieving the tasks and showing it. This file was custom made and was not in the GitHub repo. Instead, the file that was in the repo was the one that looks like this:
Because that one shows all of the tasks from all of the hosts, I made another PHP file to replicate the format I used in my website but instead of having to manually type each machine there, I made the php file use some functions and loops to retrieve the machines and tasks from the database. The result is the following:
Looks better, right?
Let’s take a look at the code:
First, I made a separate file called
config.php to keep the MySQL details there. I’m also using a global
mysqli object. Because of this change, I modified the original BOINC Tasks PHP script:
After doing that, I wrote the next file, which I called
There’s 3 functions in this file:
This function gets the machines from the MySQL database and it’s used to print the machine list, which is printed with a clickable link that goes to the machine table that shows the BOINC Tasks
After getting and printing the machine list, we call this function which will then call the next function I’ll mention below.
function getTasksPerMachine($mysqli, $machine)
This function will get the BOINC tasks that a specific machine is running. It generates the table and prints the header as well.
Those are the functions. Next, we call them to print the neatly formatted document with these 2 lines:
The first one calls the
printMachinesLinls($mysqli) function to print the machine list and the second line is the one that calls the function that generates the tables.
The software that populates the database:
I also did some updates to this software. First, I made
TruncateTables a function which will return True if it was successful truncating the table, and False if it wasn’t:
Also, I added a
NotifyIcon element to hide the software in the system tray and added a function to run the software when we pass the
-s argument. This way, the software can be programmed for the Task Scheduler tool so it is launched in a minimized way and start retrieving the tasks:
Then, I also made the Fetch button a Stop button. Clicking it after the software is running and is fetching the tasks will stop the process:
Also, I refactored some code:
And that’s it for the software changes. Basically I improved it in some ways. The page is now dinamically updated instead of manually updating which is a real plus for me. No more coding in the page! I just need to add and alter the machine list in the software and that’s it! The page will get updated with the machines listed in the software which it was able to connect and retrieve the tasks successfully.
Because the PHP files are very simple and straightforward, you can copy the file content into another page or add some styling. In my case, I integrated it with Drupal by making a PHP content page there.
The PHP Files shown in this post can be found here.
You can see how the script looks integrated into WordPress here.
What next should I do with this? I’ve yet to know 🤔
Hope you like this!