Help - Search - Members - Calendar
Full Version: Discovering server platform
Weborum Webmaster Forum > Web Page Design > PHP
sjthomas
Is there anyway in PHP to distiunguish between the platform the server is running on? I imagine its somehting like $_php['server'] but I'm not sure. basically I want something like this psuedo-code:

PHP

<?php
if ($server == "Windows") {
//  Do Windowy type stuff like a BSOD
} elseif ($server == "*nix") {
  
// do nix stuff like print out pages of helps files
} else {
  
//  Do the default
}
?>



Anyone got any ideas? Its got to be able to "tar" all *nix distros and Windows Distros "with the same brush" as the code I need to implement is to do with the file system on the server. So I don't need to know whether they are running Red Hat or Mandrake or Windows 98 or SUSE just whether its *nix or Windows. I'm sure theres a simple way of doing this but I'm damned if I can find it!

Cheers
aviansuicide
Whats the functionality your trying to implement?The nearest I can think of would be :

PHP

$_SERVER["SERVER_SOFTWARE"];




the first bracketed statement in that variable suffices for the os.

But explain what your trying to do...there may be(and probably is) a better way to do it than that.
sjthomas
Well basically I'm using a passthru function in php to call in an external executable file. The problem is that when using windows you have to use a file with it but with *nix you can just echo out a variable to be passed to it. So basically I want one statement on a Windows box and another on a *nix box. This is an example:

PHP
passthru("includes\bin\dot.exe -Tsvg < $dotFile");


Works on Windows wheer dotFile is a file but

PHP
passthru("echo '$f' | /includes/bin/dot -Tsvg ");


Works in *nix where f is the information I want to use. They don't work well (if at all) on the other platform and these two ways are the best. So basically I want to run the top one on Windows serves and the bottom one on *nix.
aviansuicide
The only thing I can think of is put that bit of code in an include file(or a function/class) and have THEM download the right file.Sorry.
aviansuicide
I'd end up doing

PHP

<?
/* Config File */

$os = 'Linux';
?>


PHP

<?
/* File where script is executed */

$passthru->{$GLOBALS["os"]}();
?>



and where passthru is:

PHP

<?
class Passthru
{
var
$winstr = '';
var
$nixstr = '';
function
Passthru($winstr,$nixstr)
{
$this->winstr = $winstr;
$this->nixstr = $nixstr;

}
function
Linux()
{
return
passthru($this->nixstr);
}
function
Windows()
{
return
passthru($this->winstr);
}
}

$passthru = new Passthru("includes\bin\dot.exe -Tsvg < $dotFile","echo '$f' | /includes/bin/dot -Tsvg");
?>

sjthomas
Hmmm, never really thought of doing it like that, its quite a good idea actually. I think I'll mess around with it a bit though andtry it out. Only problem is that its a bit of a nightmare trying to test it on *nix and Windows at anywhere near the same time. Ihave Fedora Core Linux running locally along with XP but the end system is going to be a solaris unix server/windowws 2003 server. Should be interesting! laugh.gif
aviansuicide
QUOTE(sjthomas @ Mar 26 2005, 04:51 PM)
Hmmm, never really thought of doing it like that, its quite a good idea actually.  I think I'll mess around with it a bit though andtry it out.  Only problem is that its a bit of a nightmare trying to test it on *nix and Windows at anywhere near the same time.  Ihave Fedora Core Linux running locally along with XP but the end system is going to be a solaris unix server/windowws 2003 server.  Should be interesting! laugh.gif
[right][snapback]25287[/snapback][/right]



Well...the thing is..."echo" is available on any linux server.And correct me if I'm wrong, but your 'passthru' script is one you wrote yourself, yes?So provided that doesn't contain any specific references to the Fedora file structure, you should be fine.We run CentOs...but I used to admin RHEL servers.I've never used Solaris, tho.
sjthomas
passthru is actually a PHP function available since PHP 3 (http://uk2.php.net/manual/en/function.passthru.php). its actually very powerfull and I'm surprised more people don't use it. And yeah th eproblem is that ot does contain a reference to the file structure, thats been the crux of my problems!
aviansuicide
QUOTE(sjthomas @ Mar 26 2005, 07:36 PM)
passthru is actually a PHP function available since PHP 3 (http://uk2.php.net/manual/en/function.passthru.php).  its actually very powerfull and I'm surprised more people don't use it.  And yeah th eproblem is that ot does contain a reference to the file structure, thats been the crux of my problems!
[right][snapback]25297[/snapback][/right]


Um..dude..I know what passthru is.I was referring to the /includes/blah part of the argument ^_~

I don't use it because I don't need it.I may when I start work on my next big project(server administration panel,eg: CPanel but better ^_~).

Hmm...if you don't feel comfortable posting it -- why don't you pm me the info on exactly what it does(and the shell script version of the code) and I'll see if I have any ideas as to how to remove that crux?
sjthomas
QUOTE(aviansuicide @ Mar 26 2005, 11:39 PM)
QUOTE(sjthomas @ Mar 26 2005, 07:36 PM)
passthru is actually a PHP function available since PHP 3 (http://uk2.php.net/manual/en/function.passthru.php).  its actually very powerfull and I'm surprised more people don't use it.  And yeah th eproblem is that ot does contain a reference to the file structure, thats been the crux of my problems!
[right][snapback]25297[/snapback][/right]


Um..dude..I know what passthru is.I was referring to the /includes/blah part of the argument ^_~

I don't use it because I don't need it.I may when I start work on my next big project(server administration panel,eg: CPanel but better ^_~).

Hmm...if you don't feel comfortable posting it -- why don't you pm me the info on exactly what it does(and the shell script version of the code) and I'll see if I have any ideas as to how to remove that crux?
[right][snapback]25299[/snapback][/right]


lol sorry man, bit of a misunderstanding there lol

The script that is being pass throughed (is that even a word!?!?!?) is the graphviz program (or the dotty program from the Graphviz project anyway) thats here:
http://www.graphviz.org/
Its a program for automatic graph layouts that I'm using for a project. The problem is that its going to be in locations that I don't control (on web servers) but its likely to be in the same place every time I run it in Windows and the same place when I run it on Solaris. I'm just going to assign a global variable in my configuration file and check that when using passthru and doing other stuff that relates to files. I think its just going to be easier that way. See Im always changing the code on either Windows OR Solaris so I always end up having to hack my way through the code to change all the file related code and passthru functions when I change platforms. Its a bit of a nightmare so I was trying to figure out a better way to deal with it. Which I think is your suggestion! biggrin.gif
aviansuicide
Glad to suggest something helpful XD.But..in all honesty..I don't see why your bothering with an external program when you could just use a php script.
sjthomas
QUOTE(aviansuicide @ Mar 27 2005, 12:21 AM)
Glad to suggest something helpful XD.But..in all honesty..I don't see why your bothering with an external program when you could just use a php script.
[right][snapback]25310[/snapback][/right]


You mean for the graph generation? Well the generating isn't the hard but its the layout which is what this tool is really all about. It handles all the model/graph layout and positioning for you which is very nice. Thats not something I particularly want to do in PHP when Graphviz works so very very well.
aviansuicide
*shrugs* As you wish.I never had much use for generating graphs...so I guess you know what you need.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2008 Invision Power Services, Inc.