Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#16 2008-01-02 20:46:28

jstubbs
Member
From: Hong Kong
Registered: 2004-12-13
Posts: 2,395
Website

Re: rvm_css (v1.2)

Fixed. Thanks Ruud.

Offline

#17 2008-01-02 20:49:59

zero
Member
From: Lancashire
Registered: 2004-04-19
Posts: 1,475
Website

Re: rvm_css (v1.2)

Would this be worthwhile if using a php styleswitcher? I have this code in the head of the page. I can change txp:css but how would I alter the other code and would it be any good anyway?

<style type="text/css" media="screen,projection">
@import "<txp:site_url />textpattern/css.php?n=default";
</style>
<txp:php>
global $prefs;
$cookie_s1 = cs('s1');
$cookie_s2 = cs('s2')
;
if ($cookie_s2) {
echo n.'<link rel="stylesheet" type="text/css" media="screen,projection" href="'.hu.'textpattern/css.php?n='.$cookie_s2.'" />';
}
if ($cookie_s1) {
echo n.'<link rel="stylesheet" type="text/css" media="screen,projection" href="'.hu.'textpattern/css.php?n='.$cookie_s1.'" title="'.$cookie_s1.'" />';
}
</txp:php>
<txp:css format="link" rel="alternate stylesheet" media="screen,projection" n="c" title="cool" />
<txp:css format="link" rel="alternate stylesheet" media="screen,projection" n="w" title="warm" /> 
etcetera

Dozy P My attempt at music

Offline

#18 2008-01-02 21:14:41

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: rvm_css (v1.2)

peter, you’re loading 3 – 5 style sheets so rvm_css would give a huge speed increase (saves 3 – 5 times the overhead of starting PHP and TXP to get a style sheet). The fact that your template contains a PHP style switcher doesn’t matter. It’s not the switching part that benefits, but the speed of loading the individual stylesheets:

@import "<txp:rvm_css n="default" />";

and replace <txp:css with <txp:rvm_css in all other places (see plugin help for other steps required after installation).

Offline

#19 2008-01-02 22:32:55

zero
Member
From: Lancashire
Registered: 2004-04-19
Posts: 1,475
Website

Re: rvm_css (v1.2)

Brilliant! Thank you, Ruud! It’s all working great!


Dozy P My attempt at music

Offline

#20 2008-01-03 13:30:38

net-carver
Archived Plugin Author
Registered: 2006-03-08
Posts: 1,648

Re: rvm_css (v1.2)

Ruud

thank you for yet another useful plugin.

Quick question: should plugins or mods assume the directory separator character is ‘/’ or should they use the DS definition of a directory separator as defined in constants.php? AFAIK, Windows uses ‘\’ as its path separator.

I’d like to know because I do use the ‘DS’ definition for directory separators in some of my own plugins and just wondered what the developers take on it is.

In fact, is the ‘DS’ is even needed at all (ie can Windows survive a ‘/’ separated file path without choking.)?

Many thanks in advance,


Steve

Offline

#21 2008-01-03 14:28:46

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: rvm_css (v1.2)

As I understand it, windows accepts both / and \ (but I can’t test in windows)
In TXP sometimes DS is used, sometimes a hardcoded / is used.

Offline

#22 2008-01-03 14:34:53

net-carver
Archived Plugin Author
Registered: 2006-03-08
Posts: 1,648

Re: rvm_css (v1.2)

Ruud

As I understand it, windows accepts both / and \ (but I can’t test in windows)

Thank you.


Steve

Offline

#23 2008-01-03 15:32:44

wet
Developer Emeritus
From: Vöcklabruck, Austria
Registered: 2005-06-06
Posts: 3,421
Website GitHub Mastodon

Re: rvm_css (v1.2)

Yes, Windows accepts both characters as an input path delimiter, but you should be extra careful if you process directory paths which were read as an OS output. It depends on the consistent use of DS in both path building and path processing code whether your code works cross platform.

Case in point is for instance here which didn’t work in Windows in its previous incarnation with hardcoded directory separators.

Offline

#24 2008-01-03 15:47:08

net-carver
Archived Plugin Author
Registered: 2006-03-08
Posts: 1,648

Re: rvm_css (v1.2)

Ruud, Wet

Thank you both for answering my questions. I’ll be sticking with using the DS definition after reading your posts.

Ruud

Sorry if this seems to be hijacking your plugin thread but my question was honestly triggered by your code. I think in future I’ll start a new thread for any similar issues arising.


Steve

Offline

#25 2008-01-03 16:28:52

thebombsite
Archived Plugin Author
From: Exmouth, England
Registered: 2004-08-24
Posts: 3,251
Website

Re: rvm_css (v1.2)

I’m not sure if I’m on the right tack here Steve but I think it depends on where you are within the “system” for example in my xamplite install I need to use C:\xampplite\htdocs\designer\files and something similar for the temp file path (also the path to textpattern in the config.php file) however all other links ie navigation etc are “/” which may be because they are within the PHP environment?? Anyway I have no problems with plug-ins.

Last edited by thebombsite (2008-01-03 16:31:55)


Stuart

In a Time of Universal Deceit
Telling the Truth is Revolutionary.

Offline

#26 2008-01-03 16:48:38

net-carver
Archived Plugin Author
Registered: 2006-03-08
Posts: 1,648

Re: rvm_css (v1.2)

Stuart

A little confusing. I’ll try to explain it…

URLs such as the navigation links will be ‘/’ as that’s what the URL spec says they need to be. However, file-path delimiters are different and controlled by the OS writers with no universal standard. On *nix the ‘/’ character is used and on Windows the ‘\’ character is the one used.

If I understand correctly, Wet was pointing out that whilst you can say to Windows “go to C:\My Documents” or “go to C:/My Documents” it will do so but when you ask “Where am I?” it will then say “C:\My Documents” — using the ‘\’ character.

Result, plugin writers who want cross-OS compatible plugins that deal with file-paths need to be careful to compare against the correct OS specific path delimiter when they get paths from the OS. That can easily be taken care of by using the DS definition instead of hard-coding ‘/’ or ‘\’ characters into the plugin.

Last edited by net-carver (2008-01-03 16:51:14)


Steve

Offline

#27 2008-01-03 17:11:24

thebombsite
Archived Plugin Author
From: Exmouth, England
Registered: 2004-08-24
Posts: 3,251
Website

Re: rvm_css (v1.2)

Got it. :)


Stuart

In a Time of Universal Deceit
Telling the Truth is Revolutionary.

Offline

#28 2008-01-03 22:55:39

nardo
Member
From: tuvalahiti
Registered: 2004-04-22
Posts: 743

Re: rvm_css (v1.2)

net-carver – not sure if this is relevant; but can confirm ruud’s plugin working on IIS server – and working great!!

Offline

#29 2008-01-06 01:39:01

hcgtv
Archived Plugin Author
From: Key Largo, Florida
Registered: 2005-11-29
Posts: 2,722
Website

Re: rvm_css (v1.2)

Ruud,

Just got a chance to try this out on a new site running r2762.

Decided to run Apache Bench: ab -c 5 -n 100 http://mysite.com

Without the plugin:
Concurrency Level: 5
Time taken for tests: 2.903062 seconds
Complete requests: 100
Failed requests: 0
Write errors: 0
Total transferred: 326500 bytes
HTML transferred: 301600 bytes
Requests per second: 34.45 1 (mean)
Time per request: 145.153 [ms] (mean)
Time per request: 29.031 [ms] (mean, across all concurrent requests)
Transfer rate: 109.54 [Kbytes/sec] received

With the plugin:
Concurrency Level: 5
Time taken for tests: 3.412726 seconds
Complete requests: 100
Failed requests: 0
Write errors: 0
Total transferred: 325800 bytes
HTML transferred: 300900 bytes
Requests per second: 29.30 1 (mean)
Time per request: 170.636 [ms] (mean)
Time per request: 34.127 [ms] (mean, across all concurrent requests)
Transfer rate: 93.18 [Kbytes/sec] received

Webserver specs:
  • Apache 2.2.6 – HTTP server
  • MySQL 5.0.51 – Database server
  • PHP 5.2.4 – Web scripting language
  • APC 3.0.16 – Alternative PHP Cache

This particular server is running the APC (opcode cache), since css.php is already cached, could having to go out to disk to retrieve the css file be slowing it down?

Offline

#30 2008-01-06 09:04:46

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: rvm_css (v1.2)

Bert, try benchmarking the difference between loading css.php and the static stylesheet.css file instead. When using ‘ab’ as you are, it only benchmarks the loading of the main website HTML code, but not the loading of the style sheet.

For the main website, the difference for the normal website page in execution speed should be at most: 1 SQL query (retrieving the stylesheet name from the DB is not a complex query so it should be fast) and 1 filesystem call to check if the stylesheet file is present and can be read (the result should be cached by the filesystem).

When using an opcode cache I’m guessing the difference between css.php and a static style sheet is less, but the static file should still be a lot faster if you have enough RAM to cache, because then it will be cached by the OS in RAM.

Hmm… I’m wondering if you’d get a speed increase by putting the plugin code in the plugin_cache directory, because then APC can cache it. If it has to be loaded from the database and then eval-ed, I suspect APC can’t cache it. This is only the loading of the plugin I’m talking about here, btw, not the actual use of the plugin.

Offline

Board footer

Powered by FluxBB