Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2010-02-10 21:16:15

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,392
Website GitHub

TXP on Windows

Just browsing the core and checking the PHP reference manual I noticed a possible trip-up point. In txplib_misc.php there’s a function called is_windows() defined thusly:

return (PHP_OS == 'WINNT' or PHP_OS == 'WIN32' or PHP_OS == 'Windows');

Cross-referencing this with the PHP manual I was led to a description of a function called php_uname. The first sentence states:

php_uname() returns a description of the operating system PHP is running on. This is the same string you see at the very top of the phpinfo() output. For the name of just the operating system, consider using the PHP_OS constant, but keep in mind this constant will contain the operating system PHP was built on.

I guess 99% of the time PHP will be built on the same system it is running on, but could there be a situation where this is not the case? Should our is_windows() function use php_uname('s') instead? If not that, should it be defined as they suggest like this:

return (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN');

That’s 2 function calls versus 2 logical operators — so probably slower. The function is_windows() itself is used primarily (at least has most impact) in date / time formatting functions like <txp:posted />. I just wonder what will happen if Windows 7 or some future version reports itself as Windows-super-crunjo-ultimate-hatstand, or perhaps the 64-bit version returns WIN64. Are we more likely to be covered by altering it, despite the slight speed impact? Of course if speed’s a problem we could cache the value after first use.

Does anyone have any authority or viewpoint on this? I’m a *nix geek and never run Win in a server environment so don’t know if this matters.

Last edited by Bloke (2010-02-10 21:16:32)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#2 2010-02-11 06:50:50

wet
Developer Emeritus
From: Schoerfling, Austria
Registered: 2005-06-06
Posts: 3,328
Website Mastodon

Re: TXP on Windows

Bloke wrote:

I guess 99% of the time PHP will be built on the same system it is running on, but could there be a situation where this is not the case?

I don’t think so. PHP for Windows is built with either VC6 or VC9, which is as anti-cross-platform as one can imagine.

VC6 Versions are compiled with the legacy Visual Studio 6 compiler. VC9 Versions are compiled with the Visual Studio 2008 compiler. (Source )

Offline

#3 2010-02-11 11:54:58

Mary
Sock Enthusiast
Registered: 2004-06-27
Posts: 6,236

Re: TXP on Windows

Robert is correct – if you run PHP on Windows, it was definitely built on Windows.

And I run on Windows 7 64 bit, and php_uname() still reports “Windows NT” as the beginning of the string.

But yes, you can definitely simplify this. Perhaps make a new IS_WIN entry in constants.php? Then replace the use of is_windows() in Txp with IS_WIN.Keep the is_windows() function for backwards compatibility w/plugins, but just change it to return the constant value?

Offline

#4 2010-02-11 15:22:09

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,392
Website GitHub

Re: TXP on Windows

Thanks for the insights. Wasn’t sure if some fool might build PHP locally on WinXP and then upload the lot to a Windoze server running Win7 (“it’s all Windows… right?”). Saves headaches for us if that scenario won’t happen and — as you say — PHP’s functions seem to respond in a uniform way anyway.

That’s a good suggestion about the IS_WIN constant, Mary. Much neater solution; I’ll give it a whirl, thanks.

Last edited by Bloke (2010-02-11 15:23:17)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

Board footer

Powered by FluxBB