Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

PHP advice please

Name: Anonymous 2008-04-16 20:18

Hi guys newbie PHP guy here and I wanted an experienced persons opinion on how I did on this little page (the teamspeak function is not mine but leeched source(inb4 idiots and flamers)


<html>
<head>
<title>Status</title>
</head>
<body bgcolor=black text=green>
<p>

<?php

$avgpath = "/proc/loadavg";
$avghandle = fopen($avgpath, "r");
$avgread = fread($avghandle, 15);
fclose($avghandle);
$avgout = explode(" ", $avgread);

$freespace = disk_free_space("/home");
$totalspace = disk_total_space("/home");
$freeout = $freespace/1024/1024/1024;
$totalout = $totalspace/1024/1024/1024;

function check_ts($ip, $tcp, $udp, $timeout=1) {
$tsinput = @fsockopen($ip, $tcp, $errno, $errstr, $timeout);
@fclose($tsinput);
}

function check_irc($ip, $tcp, $timeout=1) {
$ircinput = @fsockopen($ip, $tcp, $errno, $errstr, $timeout);
@fclose($ircinput);
}

echo "<br />";
echo "Server load averages: $avgout[0] $avgout[1] $avgout[2]";
echo "<br /><br />";

echo "Free harddrive space: ";
echo floor($freeout);
echo " GB <br />";
echo "Total harddrive space: ";
echo floor($totalout);
echo " GB <br /><br />";

if(check_ts("localhost", 51234, 8767)) {
echo "Teamspeak is currently online<br />";
}
else {
echo "Teamspeak is currently offline<br />";
}

if(check_irc("localhost", 6667)) {
echo "IRC is currently online<br />";
}
else {
echo "IRC is currently offline<br /><br />";
}

?>

<a href="javascript:window.close()">Close me</a>

</p>
</body>
</html>

Name: GJS Jay Sussman !AkWkaH0dT. 2008-04-16 20:24

If IHNBT, please ask a specific question.

Name: Anonymous 2008-04-16 20:28

What does IHNBT mean?

And I just would like a person to look over my script and give me any advice where I could do something better/more efficient and whatnot 

Name: Anonymous 2008-04-16 20:29

gb2/g/

Name: Anonymous 2008-04-16 20:30

Want advice? Don't use PHP. PHP is a shitty, horribly inefficient mess of what can barely be considered a programming language. The only reason PHP is widely used (or seems to be widely used) is the ease with which it can be deployed. It has no other redeeming qualities.

If you have a specific question, ask it.

Name: Anonymous 2008-04-16 20:30

It is great!

DON'T HELP HIM!!!

Name: Anonymous 2008-04-16 20:33

I use PHP because it reminds me of C and I just want advice/pointers

Name: Anonymous 2008-04-16 20:35

>>7
If you want pointers, you should go back to C.

Name: Anonymous 2008-04-16 20:38

>>8
I was gonna create this meme, but I thought I would let you have the opportunity.

Name: Anonymous 2008-04-16 20:40

hmm you guys are as useful as /g/ which figures because 4chan is full of retards anymore

Name: Anonymous 2008-04-16 20:40

>>10
back to /b/, then

Name: Anonymous 2008-04-16 20:41

anymore
Invalid qualifier for this context.

Name: Anonymous 2008-04-16 20:42

>>12
use strict; turn on.

Name: Anonymous 2008-04-16 20:42

http://imgs.xkcd.com/comics/delicious.png

and so life imitates xkcd

Name: Anonymous 2008-04-16 21:03

>>1
First part may as well be
echo `df -h`
As for the check_ts function you don't use the $udp variable.
Other than that, check_ts and check_irc are the same.
Notice a pattern?
You should have checkhost() instead. (by the way, SICP is quite good at teaching you how to find patterns and write generic and abstract procedures, albeit a bit advanced for you it seems)
$udp and $tcp are retarded variable names, especially when what they really are is a port number.
Both TCP and UDP (and SCTP) support ports.
I suggest you have something like
checkhost($host, $protocol, $port).
$host should be IPv4, IPv6 or host name.
$protocol could be some constant that tells you if you use tcp, udp or sctp or something else. (I doubt fsockopen() supports sctp)
$port.. the port


Anyway, the code is fucking retarded. I have a hard time believing you are not a troll.

Name: Anonymous 2008-04-16 21:05

>>1
My advice to you is to start drinking heavily.


Also, use something that isn't PHP. Anything. Fuck, even that abortion called Ruby On Rails. It's still better than PHP.

Name: Anonymous 2008-04-16 21:13

>>16
Would you give up your high horse and write enterprise PHP code for $40,000 a year?

Name: Anonymous 2008-04-16 21:18

>>17
No, I make more than that.

Name: Anonymous 2008-04-16 21:43

>>17
I make more than that. I thought it was a lot and then realised it was dollars, divided by two, and achieved satori.

Name: Anonymous 2008-04-16 21:55

>>17
LOL! I make $85kUSD writing C#.

So... FUCK NO.

Name: Anonymous 2008-04-16 23:00

>>8
Not true, php has &

Name: Anonymous 2008-04-16 23:05

>>16
Honestly, I would rather code in PHP than Ruby on Rails.

Name: Anonymous 2008-04-17 4:51

>>22
You should try a REAL language instead of toy languages one day.

Name: Anonymous 2008-04-17 8:05

Name: Trollbot9000 2009-07-01 8:33

The one true FrozenVoid!

Name: Sgt.Kabukiman 2012-05-22 7:33

All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy

Don't change these.
Name: Email:
Entire Thread Thread List