Welcome Guest, Not a member yet? Register   Sign In
Server status with Codeigniter
#11

[eluser]Watermark Studios[/eluser]
You can keep it simple and just do a controller -> view implementation. That would be fastest for what you are trying to do. If you plan to expand it at all, I would personally put the ping function into a model for encapsulation/portability reasons. Especially if you plan to keep the $host_to_ping values in a database. But, sometimes "best practices" are overkill if you are doing something that can be accomplished in 17 lines. I'm just a stickler for OOP standards.
#12

[eluser]JHackamack[/eluser]
I took it off a site that was procedural. Watermark Studios had a good idea of putting it in a model, but something like that can also live in a Helper function and still be usable.
#13

[eluser]DephNet[Paul][/eluser]
[quote author="JHackamack" date="1287552406"]I took it off a site that was procedural. Watermark Studios had a good idea of putting it in a model, but something like that can also live in a Helper function and still be usable.[/quote]Would using a class work too? If so I will probably go down that route.

Many thanks for your help both of you.
#14

[eluser]JHackamack[/eluser]
You can use anything as long as you can access it. CodeIgniter is pretty flexible that way so it's all up to you.
#15

[eluser]Watermark Studios[/eluser]
Hmmm...a helper function would be a great idea.
#16

[eluser]DephNet[Paul][/eluser]
Hi again,

I have decided to use a library for this and have come up with the following code, which works as it is:
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Status {

    function ping()
    {
    $ip = gethostbyname("google.com");

    echo "                    <tr style=\"background-color:{row_color}\">\n";
    echo "                        <td>{server_name}</td>\n";
    echo "                        <td>" . $ip . "</td>\n";
    echo "                        <td>{server_location}</td>\n";
    echo "                        <td style=\"text-align:center;\"><img ></td>\n";
    echo "                    </tr>\n";
    }
}

/* End of file status.php */
/* Location: ./system/application/libraries/status.php */
Now, if I change gethostbyname() to use "{server_name}" rather than hard code the hostname used, I get the hostname returned, and not the IP that the hostname resolves to.

Is that expected, or is there something stupid I am doing?
#17

[eluser]JHackamack[/eluser]
I believe PHP is executed before the template stuff, so it's trying failing because it doesn't have anything to check against.
#18

[eluser]DephNet[Paul][/eluser]
Me again,

Thank you both for your help, I have finished the first version of this script and it is working as it should. If you want a look it is on http://status.fsirc.net.
#19

[eluser]Watermark Studios[/eluser]
Looking good
#20

[eluser]JHackamack[/eluser]
Pretty cool.




Theme © iAndrew 2016 - Forum software by © MyBB