php-general Digest 8 Jan 2010 19:30:54 -0000 Issue 6528

Topics (messages 300898 through 300917):

How to write specification
        300898 by: Dušan Novaković
        300899 by: David Otton

Re: PHP programming strategy; lots of little include files, or a few big ones?
        300900 by: Graham Cossey
        300913 by: Andrew Ballard
        300915 by: Robert Cummings
        300916 by: Robert Cummings
        300917 by: J Ravi Menon

trying to launch kate from the browser....
        300901 by: Rene Veerman
        300902 by: Rene Veerman
        300903 by: Ashley Sheridan
        300904 by: Rene Veerman
        300905 by: Ashley Sheridan
        300906 by: Stuart Dallas
        300907 by: Rene Veerman
        300908 by: Rene Veerman
        300909 by: Bob McConnell
        300910 by: Rene Veerman
        300911 by: Rene Veerman
        300912 by: Rene Veerman
        300914 by: Jochem Maas

Administrivia:

To subscribe to the digest, e-mail:
        php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
        php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
        php-gene...@lists.php.net


----------------------------------------------------------------------
--- Begin Message ---
Hi,

I've been programing for some time, but I never tried to write code
for two different application in same way. How when I work with more
programmers it's even worse. Everyone is forcing it's way of writing
functions inside classes or writing variables, etc. My idea is to code
according to the standard protocol so that in future it would be
easier to make applications. Is there some specification (or standard)
how to write code for web application, but which describes all
possibilities(writing css, JS, php, etc.)?

Thanks in advance,
Dusan

-- 
made by ndusan

--- End Message ---
--- Begin Message ---
2010/1/8 Dušan Novaković <ndu...@gmail.com>:

> I've been programing for some time, but I never tried to write code
> for two different application in same way. How when I work with more
> programmers it's even worse. Everyone is forcing it's way of writing
> functions inside classes or writing variables, etc. My idea is to code
> according to the standard protocol so that in future it would be
> easier to make applications. Is there some specification (or standard)
> how to write code for web application, but which describes all
> possibilities(writing css, JS, php, etc.)?

Specification and coding standard are two different things... I think
you're looking for a coding standard. Some helpful links:

http://framework.zend.com/manual/en/coding-standard.html
http://pear.php.net/manual/en/standards.php
http://drupal.org/coding-standards
http://www.dagbladet.no/development/phpcodingstandard/ [last updated
2003 - obsolete?]

Pick one (at random if necessary) and don't make any changes. Changes
imply discussion, and discussion is a waste of time.

You can enforce a coding standard, should you so wish, at repository level:

http://pear.php.net/manual/en/package.php.php-codesniffer.intro.php
http://svnbook.red-bean.com/nightly/en/svn.reposadmin.create.html#svn.reposadmin.create.hooks

--- End Message ---
--- Begin Message ---
On Fri, Jan 8, 2010 at 3:48 AM, Robert Cummings <rob...@interjinn.com> wrote:

>
> They almost always make your shit run faster.

I love your final statement Robert!
A reply of good grammar and vocabulary summarised most succinctly.


-- 
Graham

--- End Message ---
--- Begin Message ---
On Thu, Jan 7, 2010 at 10:48 PM, Robert Cummings <rob...@interjinn.com> wrote:
> ...
> They almost always make your shit run faster.

You know they make medicine for that?   ;-)

Andrew

--- End Message ---
--- Begin Message ---
Graham Cossey wrote:
On Fri, Jan 8, 2010 at 3:48 AM, Robert Cummings <rob...@interjinn.com> wrote:

They almost always make your shit run faster.

I love your final statement Robert!
A reply of good grammar and vocabulary summarised most succinctly.

:)


--
http://www.interjinn.com
Application and Templating Framework for PHP

--- End Message ---
--- Begin Message ---
clanc...@cybec.com.au wrote:
On Thu, 07 Jan 2010 22:48:59 -0500, rob...@interjinn.com (Robert Cummings) 
wrote:

clanc...@cybec.com.au wrote:
Thank you all for your comments. I did not know about bytecode caches. They're 
an
interesting concept, but if I am interpreting the paper
http://itst.net/654-php-on-fire-three-opcode-caches-compared correctly they 
only double
the average speed of operation, which is rather less than I would have anticipated.
I strongly advise that you take the time to try a bytecode cache. Within linux environments I am partial to eaccelerator. In IIS environments I now use WinCache from Microsoft. From my own observations with a multitude of different types of PHP web applications I find that the speed gain is closer to 5 times faster on average.

Five times faster is certainly more attractive than twice as fast. But under 
what
circumstances is this achieved? Unfortunately these days it is difficult to 
find any solid
information on how things actually work, but my impression is that caches only 
work for
pages which are frequently accessed. If this is correct, and (as I suspect) 
somebody looks
at my website once an hour, the page will not be in the cache, so it won't 
help. Also one
of the more popular parts of this website is my photo album, and for this much 
of the
access time will be the download time of the photos. Furthermore as each 
visitor will look
at a different set of photos, even with heavy access it is unlikely that any 
given photo
would be in a cache.

A particular cache of bytecode is usually pushed out of memory when the configured maximum amount of memory for the bytecode cache is about to be exceeded. Additionally, the particular cache that gets eliminated is usually the oldest or least used cache. Given this, and your purported usage patterns, your pages will most likely remain in the cache until such time as you update the code or restart the webserver.

Despite these comments the access times for my websites seem to be pretty good 
--
certainly a lot better than many commercial websites -- but have a look at
http://www.corybas.com/, and see what you think. (I am in the process of 
updating this,
and know that the technical notes are not currently working, but there is 
plenty there to
show you what I'm trying to do.)

I'm not disputing your good enough statistics. I'm merely asserting that a bytecode cache will resolve your concerns about file access times when your code is strewn across many compartmentalized files. In addition, I am advising that it is good practice to always install a bytecode cache. One of the first things I do when setting up a new system is to ensure I put an accelerator in place. Once it's in place, no matter how many pages or sub sites I put up, the accelerator is already in place and providing benefits.

Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP

--- End Message ---
--- Begin Message ---
Hi,

A note on bytecode caching and include/include_once performance. A
while ago when we were profiling our code, we did notice that file
includes do take a noticeable percentage of overall overhead (enough
for us to look into it more deep). We are using apc cache on a
standard LAMP platform (linux 2.6 series, apache 2.2x and PHP 5
series).

Our includes were using 'relative' paths (e.g.  include_once
'../common/somefile.inc' or include_once 'lib/somefuncs.inc' ) and
within APC cache logic, it resolves such relative paths to absolute
paths via a realpath() calls. This can be fairly file-system intensive
(lots of syscalls like stat() and readlink() to resolve symlinks
etc...). APC uses absolute paths as key into the opcode cache.

This gets worse if it has to find your files via the 'ini_path'
setting (and most of your library or common code is not in the first
component or so ).

So from APC cache perspective, it is most efficient if your include
paths are all absolute (realpath() logic is skipped) - e.g.:

include_once $BASE_DIR . '/common/somefile.inc';
include_once $BASE_DIR . '/lib/somefuncs.inc';

and so on where '$BASE_DIR' could be set via apache Setenv directives
( $_SERVER['BASE_DIR'] or even hardcoded all over the place).

There were other issues with include vs include_once and apc cache,
but I don't recall why there were performance difference (with include
only even with relative paths, the performance was better, but
managing dependencies is to cumbersome).

Not sure how other bytecode cache handles relative paths but I suspect
it has to do something similar.

>From a pure code readability point of view and more automated
dependency management (as close to compiled languages as possible), I
do favor include_once/require_once strategy with absolute path
strategy, but it is not unheard of where to squeeze out maximal
performance, a giant single 'include' is done. Sometimes this is done
on prod. systems where a parser goes through and generates this big
include file, and ensure it is placed somewhere in the beginning the
main 'controller.php' (MVC model) and all other includes stripped off.

Hope this helps in making your decision.

Ravi


On Fri, Jan 8, 2010 at 8:59 AM, Robert Cummings <rob...@interjinn.com> wrote:
> clanc...@cybec.com.au wrote:
>>
>> On Thu, 07 Jan 2010 22:48:59 -0500, rob...@interjinn.com (Robert Cummings)
>> wrote:
>>
>>> clanc...@cybec.com.au wrote:
>>>>
>>>> Thank you all for your comments. I did not know about bytecode caches.
>>>> They're an
>>>> interesting concept, but if I am interpreting the paper
>>>> http://itst.net/654-php-on-fire-three-opcode-caches-compared correctly
>>>> they only double
>>>> the average speed of operation, which is rather less than I would have
>>>> anticipated.
>>>
>>> I strongly advise that you take the time to try a bytecode cache. Within
>>> linux environments I am partial to eaccelerator. In IIS environments I now
>>> use WinCache from Microsoft. From my own observations with a multitude of
>>> different types of PHP web applications I find that the speed gain is closer
>>> to 5 times faster on average.
>>
>> Five times faster is certainly more attractive than twice as fast. But
>> under what
>> circumstances is this achieved? Unfortunately these days it is difficult
>> to find any solid
>> information on how things actually work, but my impression is that caches
>> only work for
>> pages which are frequently accessed. If this is correct, and (as I
>> suspect) somebody looks
>> at my website once an hour, the page will not be in the cache, so it won't
>> help. Also one
>> of the more popular parts of this website is my photo album, and for this
>> much of the
>> access time will be the download time of the photos. Furthermore as each
>> visitor will look
>> at a different set of photos, even with heavy access it is unlikely that
>> any given photo
>> would be in a cache.
>
> A particular cache of bytecode is usually pushed out of memory when the
> configured maximum amount of memory for the bytecode cache is about to be
> exceeded. Additionally, the particular cache that gets eliminated is usually
> the oldest or least used cache. Given this, and your purported usage
> patterns, your pages will most likely remain in the cache until such time as
> you update the code or restart the webserver.
>
>> Despite these comments the access times for my websites seem to be pretty
>> good --
>> certainly a lot better than many commercial websites -- but have a look at
>> http://www.corybas.com/, and see what you think. (I am in the process of
>> updating this,
>> and know that the technical notes are not currently working, but there is
>> plenty there to
>> show you what I'm trying to do.)
>
> I'm not disputing your good enough statistics. I'm merely asserting that a
> bytecode cache will resolve your concerns about file access times when your
> code is strewn across many compartmentalized files. In addition, I am
> advising that it is good practice to always install a bytecode cache. One of
> the first things I do when setting up a new system is to ensure I put an
> accelerator in place. Once it's in place, no matter how many pages or sub
> sites I put up, the accelerator is already in place and providing benefits.
>
> Cheers,
> Rob.
> --
> http://www.interjinn.com
> Application and Templating Framework for PHP
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--- End Message ---
--- Begin Message ---
I'm working on a better var_dump (http://mediabeez.ws/htmlMicroscope/,
LGPL), and want to launch my kate editor when i click in the browser on a
line in my trace-log.

I'm trying to exec() this line, but it returns 1 (which is i believe a
general error)

echo "eeeehhh" | sudo -u rene -S /bin/sh -c "export HOME=/home/rene/ && kate
-l 21 -u
/media/500gb/data2/www/htdocs/naaah/maintenance/maintenanceLogic.php"

if i open a terminal, do

sudo su www-data

and then execute the line above,
then kate actually jumps to the right file, or opens it, etc.

but from the browser, it won't work. exec($str,$o,$r); $r===1.
i could use some help here..

--- End Message ---
--- Begin Message ---
r...@ekster:~$ uname -a
Linux ekster 2.6.31-17-generic #54-Ubuntu SMP Thu Dec 10 16:20:31 UTC 2009
i686 GNU/Linux

r...@ekster:~$ apache2 -v
Server version: Apache/2.2.12 (Ubuntu)
Server built:   Nov 12 2009 22:49:46

r...@ekster:~$ php -v
PHP 5.2.10-2ubuntu6.3 with Suhosin-Patch 0.9.7 (cli) (built: Nov 26 2009
14:42:49)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2009 Zend Technologies

r...@ekster:~$ kate -v
Qt: 4.5.2
KDE: 4.3.2 (KDE 4.3.2)
Kate: 3.3.2

--- End Message ---
--- Begin Message ---
On Fri, 2010-01-08 at 13:41 +0100, Rene Veerman wrote:

> I'm working on a better var_dump (http://mediabeez.ws/htmlMicroscope/,
> LGPL), and want to launch my kate editor when i click in the browser on a
> line in my trace-log.
> 
> I'm trying to exec() this line, but it returns 1 (which is i believe a
> general error)
> 
> echo "eeeehhh" | sudo -u rene -S /bin/sh -c "export HOME=/home/rene/ && kate
> -l 21 -u
> /media/500gb/data2/www/htdocs/naaah/maintenance/maintenanceLogic.php"
> 
> if i open a terminal, do
> 
> sudo su www-data
> 
> and then execute the line above,
> then kate actually jumps to the right file, or opens it, etc.
> 
> but from the browser, it won't work. exec($str,$o,$r); $r===1.
> i could use some help here..


If you click a link in the browser, you can't get it to open up programs
for you on your local machine. The work is done under the user of the
web server, so you won't see Kate open up at all. Kate supports all the
kio slaves, so there may be a protocal you can stream the content down
to kate, and have the link point to the file via this protocol.

Thanks,
Ash
http://www.ashleysheridan.co.uk



--- End Message ---
--- Begin Message ---
Thanks for the reply..

I only need this to work locally on the web-server for now..

So i'm calling a script through ajax routines, which would do the exec().
Since it's on the local webserver, that should work, right?

--- End Message ---
--- Begin Message ---
On Fri, 2010-01-08 at 13:48 +0100, Rene Veerman wrote:

> Thanks for the reply..
> 
> I only need this to work locally on the web-server for now..
> 
> So i'm calling a script through ajax routines, which would do the
> exec().
> Since it's on the local webserver, that should work, right?


No, the server is very different from the client, even if they are on
the same machine. I know of no way you can have an HTML link open up
software on your machine. If it were possible, that would open up a
whole world of security issues.

What about making the link something like ftp://localhost/somefile and
have an FTP server set up on the same machine. You could set up your
local machine to respond as you wish to the ftp:// link (might be easier
to configure in Konqueror)

Thanks,
Ash
http://www.ashleysheridan.co.uk



--- End Message ---
--- Begin Message ---
On 8 Jan 2010, at 12:48, Rene Veerman wrote:

> Thanks for the reply..
> 
> I only need this to work locally on the web-server for now..
> 
> So i'm calling a script through ajax routines, which would do the exec().
> Since it's on the local webserver, that should work, right?

No. When the web server runs a PHP script it has no access to the terminal of 
the logged in user. What you are trying to do is certainly possible but won't 
be easy. An easier way to do it would be to write an app and register a URL 
scheme to open with that app (whatever://localhost/filename). That app can then 
do whatever you need it to with the URL which it will get passed as an argument.

-Stuart

-- 
http://stut.net/

--- End Message ---
--- Begin Message ---
---------- Forwarded message ----------
From: Rene Veerman <rene7...@gmail.com>
Date: Fri, Jan 8, 2010 at 1:58 PM
Subject: Re: [PHP] trying to launch kate from the browser....
To: a...@ashleysheridan.co.uk


Yep, i also just thought of using ssh/ftp to remotely edit files.
I can probably configure any web-browser to open certain links with any
local program.

But for now, i'd just like to consider the case where the browser is on the
same machine as the webserver.
In that case, you should (imo) be able to use exec() called with ajax from
the browser to startup apps on that machine.


On Fri, Jan 8, 2010 at 1:49 PM, Ashley Sheridan 
<a...@ashleysheridan.co.uk>wrote:

>
> No, the server is very different from the client, even if they are on the
> same machine. I know of no way you can have an HTML link open up software on
> your machine. If it were possible, that would open up a whole world of
> security issues.
>
> What about making the link something like ftp://localhost/somefile and
> have an FTP server set up on the same machine. You could set up your local
> machine to respond as you wish to the ftp:// link (might be easier to
> configure in Konqueror)
>
>
>   Thanks,
> Ash
> http://www.ashleysheridan.co.uk
>
>
>

--- End Message ---
--- Begin Message ---
oh,

echo "blah" | sudo -u rene -S /bin/sh -c "export HOME=/home/rene/"

exec($str,$o,$r);

$r === 0.

so that works.

therefore, it must be kate itself that refuses to start up from apache's
context.
too bad $o === empty array.

any ideas are most welcome.

--- End Message ---
--- Begin Message ---
From: Rene Veerman
> From: Rene Veerman <rene7...@gmail.com>
> 
> Yep, i also just thought of using ssh/ftp to remotely edit files.
> I can probably configure any web-browser to open certain links with
any
> local program.
> 
> But for now, i'd just like to consider the case where the browser is
on the
> same machine as the webserver.
> In that case, you should (imo) be able to use exec() called with ajax
from
> the browser to startup apps on that machine.

> On Fri, Jan 8, 2010 at 1:49 PM, Ashley Sheridan
<a...@ashleysheridan.co.uk>wrote:
>>
>> No, the server is very different from the client, even if they are on
the
>> same machine. I know of no way you can have an HTML link open up
software on
>> your machine. If it were possible, that would open up a whole world
of
>> security issues.
>>
>> What about making the link something like ftp://localhost/somefile
and
>> have an FTP server set up on the same machine. You could set up your
local
>> machine to respond as you wish to the ftp:// link (might be easier to
>> configure in Konqueror)

You might be able to set kate as a helper app in the browser, but you
still have two problems.

A. How do you map the file path from the web server's docroot to the
real path? i.e. can you translate the URL into a real file path?
B. Does the browser user have access rights to that file/directory?

It's probably easier to set up NetBeans with the debugger. That
combination is designed to do what you are asking for.

Bob McConnell

--- End Message ---
--- Begin Message ---
$str = ''echo "blah" | sudo -u rene -S /bin/sh -c "export HOME=/home/rene/
&& export"'';
exec($str,$o,$r);

$r === 0.

$o =
<pre class='xdebug-var-dump' dir='ltr'>
<b>array</b>
  0 => 'export HOME=&apos;/home/rene/&apos;'
.....more.....
</pre>

--- End Message ---
--- Begin Message ---
---------- Forwarded message ----------
From: Rene Veerman <rene7...@gmail.com>
Date: Fri, Jan 8, 2010 at 2:29 PM
Subject: Re: [PHP] trying to launch kate from the browser....
To: Bob McConnell <r...@cbord.com>


A: str_replace() ;) maybe a preg_replace() but i dont think thats even
necessary.

B: the sudo (see my last mails) is successfull, and i can update the
environment too. so it executes as user rene on the webserver.
the webbrowser just tells the server which of it's own files to kick to the
kate editor.


On Fri, Jan 8, 2010 at 2:23 PM, Bob McConnell <r...@cbord.com> wrote:

> You might be able to set kate as a helper app in the browser, but you
> still have two problems.
>
> A. How do you map the file path from the web server's docroot to the
> real path? i.e. can you translate the URL into a real file path?
> B. Does the browser user have access rights to that file/directory?
>
> It's probably easier to set up NetBeans with the debugger. That
> combination is designed to do what you are asking for.
>
>

--- End Message ---
--- Begin Message ---
hmm. after a nap i'm gonna try to start the editor directly from the browser
instead, with ssh:// hopefully to get/write the file on the server.

--- End Message ---
--- Begin Message ---
Op 1/8/10 1:41 PM, Rene Veerman schreef:
> I'm working on a better var_dump (http://mediabeez.ws/htmlMicroscope/,
> LGPL), and want to launch my kate editor when i click in the browser on a
> line in my trace-log.
> 
> I'm trying to exec() this line, but it returns 1 (which is i believe a
> general error)
> 
> echo "eeeehhh" | sudo -u rene -S /bin/sh -c "export HOME=/home/rene/ && kate
> -l 21 -u
> /media/500gb/data2/www/htdocs/naaah/maintenance/maintenanceLogic.php"
> 
> if i open a terminal, do
> 
> sudo su www-data
> 
> and then execute the line above,
> then kate actually jumps to the right file, or opens it, etc.
> 
> but from the browser, it won't work. exec($str,$o,$r); $r===1.
> i could use some help here..
>

seems everyone has the wrong idea about what your trying to do. it is possible,
given that your webserver and your browser are running on the machine - if the 
webserver
manages to start Kate up then you'll see the editor on your screen.

the only problem you *seem* to have is the fact that your webserver doesn't 
have the
ness. permissions to run the exec command (I'd guess it's specifically related 
to the fact
that the user apache runs as doesn't have the perms to run sudo, at least not 
in the context
of your user account) ... try fudging your sudoers file to give the user your 
apache instance
runs as the perms to run 'sudo kate' as you ... then restart apache (just in 
case) and see what
happens.



--- End Message ---

Reply via email to