Menu
Forums
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Trending
What's new
New posts
New profile posts
Latest activity
Members
Current visitors
New profile posts
Search profile posts
Upgrades
Log in
Register
What's new
Search
Search
Search titles only
By:
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Menu
Log in
Register
Navigation
Install the app
Install
More options
Contact us
Close Menu
Forums
Software Development
Programming
[PHP] OOP Server Status
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="Markshall" data-source="post: 196875" data-attributes="member: 1872"><p>Thread moved to free programs and scripts.</p><p> </p><p>Nicely done, however, I think the idea of having the status results in the function isn't good, I'd prefer to do it this way, plus you don't even need to make it as a class, you can just have it as a bog standard function, but having it as a class does make it look smarter, so for this code snippet I'll code it in OOP.</p><p> </p><p>[PHP]<?php</p><p>class Server {</p><p> public function Status($Server, $Port) {</p><p> $Status = @fsockopen($Server, $Port, $errno, $errstr, 2);</p><p> </p><p> return $Status;</p><p> }</p><p>}</p><p> </p><p>$Server = new Server();</p><p> </p><p>$MyStatus = $Server->Status('127.0.0.1', 80);</p><p>if ($MyStatus) {</p><p> echo '127.0.0.1 is online.';</p><p>}else{</p><p> echo '127.0.0.1 is offline :(.';</p><p>}</p><p>?>[/PHP]</p><p> </p><p>Doing it that way means you can set your own success/error messages and don't have to be tied down to the ones you set in your function, if that makes sense?</p><p> </p><p>But still, nicely done.</p></blockquote><p></p>
[QUOTE="Markshall, post: 196875, member: 1872"] Thread moved to free programs and scripts. Nicely done, however, I think the idea of having the status results in the function isn't good, I'd prefer to do it this way, plus you don't even need to make it as a class, you can just have it as a bog standard function, but having it as a class does make it look smarter, so for this code snippet I'll code it in OOP. [PHP]<?php class Server { public function Status($Server, $Port) { $Status = @fsockopen($Server, $Port, $errno, $errstr, 2); return $Status; } } $Server = new Server(); $MyStatus = $Server->Status('127.0.0.1', 80); if ($MyStatus) { echo '127.0.0.1 is online.'; }else{ echo '127.0.0.1 is offline :(.'; } ?>[/PHP] Doing it that way means you can set your own success/error messages and don't have to be tied down to the ones you set in your function, if that makes sense? But still, nicely done. [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
Software Development
Programming
[PHP] OOP Server Status
Top