Re: [PHP-DEV] SplFileObject Countable

2011-03-15 Thread Nick Pope

Hi Sebastian,

Since Etienne brought it up, would it not also make sense for you to 
implement countWords() and countBytes()?


Also, unicode issues aside, it might still be nice to implement 
countChars().


And finally, so that it provides all most of the functionality of the 
GNU wc program, there could also be getMaxLineLength().  This would need 
a different name however as this method would be to count the longest 
line of the file rather than indicate the maximum length of a line to 
read as the current SplFileObject::getMaxLineLen() method does.


Just my thoughts,

Nick


On 14/03/11 22:24, Sebastian Marek wrote:

Hello,

That makes perfect sense. I have raised a feature request and have attached
a patch containing both countLines() method implementation and phpt tests.

thx

On Sun, Mar 13, 2011 at 9:39 PM, Etienne Kneusscol...@php.net  wrote:


On Mar 11 23:22:04, Sebastian Marek wrote:

Hi,

I have recently used SplFileObject to work with files. I was lacking a

bit

of functionality in there regarding counting number of lines in a given
file. Although I could just load contents of the file to an array and

check

it size, I thought it would be nice to have SplFileObject Countable.

Here is an example implementation I made tonight that seems to work well

-

https://gist.github.com/866767 . Is it something you think would be

worth

adding to the existing SplFileObject? Is the implementation any good? I
reused some of the existing logic to avoid breaking

'spl_filesystem_object'

internal integrity, but maybe it would make sense to make it work with

the

stream itself.


In my oppinion, it does not make sense to implement countable for this
use. Countable should be implemented on classes where calling count() on
them is not ambiguous, i.e. the size of a collection.

There is no reason why count() on a file should be the number of lines,
why not words, or bytes?

I'd however be happy with a new countLines() method.

Best,



If it's fine I can write some unit tests to cover this and then submit a
complete patch.

Regards
--
Sebastian Marek
proo...@gmail.com

Follow me online at:
Blog: http://criticallog.thornet.net/
Twitter: http://twitter.com/proofek
Linkedin: http://uk.linkedin.com/in/sebastianmarek
Ohloh: http://www.ohloh.net/accounts/proofek
http://twitter.com/proofek









--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] SplFileObject Countable

2011-03-15 Thread Sebastian Marek
Hello Nick,


Might be fun, I'll have a look at it. Is the stuff I have done so far any
good? I've got only a little C experience, so any feedback is good!

cheers

On Tue, Mar 15, 2011 at 9:35 AM, Nick Pope p...@nickpope.me.uk wrote:

 Hi Sebastian,

 Since Etienne brought it up, would it not also make sense for you to
 implement countWords() and countBytes()?

 Also, unicode issues aside, it might still be nice to implement
 countChars().

 And finally, so that it provides all most of the functionality of the GNU
 wc program, there could also be getMaxLineLength().  This would need a
 different name however as this method would be to count the longest line of
 the file rather than indicate the maximum length of a line to read as the
 current SplFileObject::getMaxLineLen() method does.

 Just my thoughts,

 Nick



 On 14/03/11 22:24, Sebastian Marek wrote:

 Hello,

 That makes perfect sense. I have raised a feature request and have
 attached
 a patch containing both countLines() method implementation and phpt tests.

 thx

 On Sun, Mar 13, 2011 at 9:39 PM, Etienne Kneusscol...@php.net  wrote:

  On Mar 11 23:22:04, Sebastian Marek wrote:

 Hi,

 I have recently used SplFileObject to work with files. I was lacking a

 bit

 of functionality in there regarding counting number of lines in a given
 file. Although I could just load contents of the file to an array and

 check

 it size, I thought it would be nice to have SplFileObject Countable.

 Here is an example implementation I made tonight that seems to work well

 -

 https://gist.github.com/866767 . Is it something you think would be

 worth

 adding to the existing SplFileObject? Is the implementation any good? I
 reused some of the existing logic to avoid breaking

 'spl_filesystem_object'

 internal integrity, but maybe it would make sense to make it work with

 the

 stream itself.


 In my oppinion, it does not make sense to implement countable for this
 use. Countable should be implemented on classes where calling count() on
 them is not ambiguous, i.e. the size of a collection.

 There is no reason why count() on a file should be the number of lines,
 why not words, or bytes?

 I'd however be happy with a new countLines() method.

 Best,


 If it's fine I can write some unit tests to cover this and then submit a
 complete patch.

 Regards
 --
 Sebastian Marek
 proo...@gmail.com

 Follow me online at:
 Blog: http://criticallog.thornet.net/
 Twitter: http://twitter.com/proofek
 Linkedin: http://uk.linkedin.com/in/sebastianmarek
 Ohloh: http://www.ohloh.net/accounts/proofek
 http://twitter.com/proofek







 --
 PHP Internals - PHP Runtime Development Mailing List
 To unsubscribe, visit: http://www.php.net/unsub.php




-- 
Sebastian Marek
proo...@gmail.com

Follow me online at:
Blog: http://criticallog.thornet.net/
Twitter: http://twitter.com/proofek
Linkedin: http://uk.linkedin.com/in/sebastianmarek
Ohloh: http://www.ohloh.net/accounts/proofek
http://twitter.com/proofek


Re: [PHP-DEV] SplFileObject Countable

2011-03-15 Thread Peter Cowburn
Hi all,

On 15 March 2011 09:35, Nick Pope p...@nickpope.me.uk wrote:
 Hi Sebastian,

 Since Etienne brought it up, would it not also make sense for you to
 implement countWords() and countBytes()?

For countBytes() how is that different from SplFileInfo's getSize() ?
As for countWords() and the others, I think this crosses the line (in
my view) over what a File Object should provide.


 Also, unicode issues aside, it might still be nice to implement
 countChars().

 And finally, so that it provides all most of the functionality of the GNU wc
 program, there could also be getMaxLineLength().  This would need a
 different name however as this method would be to count the longest line of
 the file rather than indicate the maximum length of a line to read as the
 current SplFileObject::getMaxLineLen() method does.

 Just my thoughts,

 Nick


 On 14/03/11 22:24, Sebastian Marek wrote:

 Hello,

 That makes perfect sense. I have raised a feature request and have
 attached
 a patch containing both countLines() method implementation and phpt tests.

Having not looked at the implementation yet, I have no comments on the
patch itself. However, I would prefer a get prefixed method name,
getLineCount() or similar.


 thx

 On Sun, Mar 13, 2011 at 9:39 PM, Etienne Kneusscol...@php.net  wrote:

 On Mar 11 23:22:04, Sebastian Marek wrote:

 Hi,

 I have recently used SplFileObject to work with files. I was lacking a

 bit

 of functionality in there regarding counting number of lines in a given
 file. Although I could just load contents of the file to an array and

 check

 it size, I thought it would be nice to have SplFileObject Countable.

 Here is an example implementation I made tonight that seems to work well

 -

 https://gist.github.com/866767 . Is it something you think would be

 worth

 adding to the existing SplFileObject? Is the implementation any good? I
 reused some of the existing logic to avoid breaking

 'spl_filesystem_object'

 internal integrity, but maybe it would make sense to make it work with

 the

 stream itself.

 In my oppinion, it does not make sense to implement countable for this
 use. Countable should be implemented on classes where calling count() on
 them is not ambiguous, i.e. the size of a collection.

 There is no reason why count() on a file should be the number of lines,
 why not words, or bytes?

 I'd however be happy with a new countLines() method.

 Best,


 If it's fine I can write some unit tests to cover this and then submit a
 complete patch.

 Regards
 --
 Sebastian Marek
 proo...@gmail.com

 Follow me online at:
 Blog: http://criticallog.thornet.net/
 Twitter: http://twitter.com/proofek
 Linkedin: http://uk.linkedin.com/in/sebastianmarek
 Ohloh: http://www.ohloh.net/accounts/proofek
 http://twitter.com/proofek






 --
 PHP Internals - PHP Runtime Development Mailing List
 To unsubscribe, visit: http://www.php.net/unsub.php



--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] preg_replace does not replace all occurrences

2011-03-15 Thread Richard Quadling
On 14 March 2011 20:36, Hannes Landeholm landeh...@gmail.com wrote:
 What is more likely to be wrong? Your understanding of a specific
 regex pattern (which happens to be full of escapes making it
 incredibly hard to read) or the implementation of preg_replace?

 ~Hannes

 On 14 March 2011 16:18, Martin Scotta martinsco...@gmail.com wrote:

 I chose the simplest example to show the preg_replace behavior, there are
 better (and safer) ways to scape slash characters.
 Anyways, *is this the expected preg_replace behavior?*

  Martin

 ?php
 function test($str) {
    static $re = '/(^|[^])\'/';
    static $change = '$1\\\'';

    echo $str, PHP_EOL,
        preg_replace($re, $change, $str), PHP_EOL, PHP_EOL;
 }

 test(str '' str); // bug?
 test(str \\'\\' str); // ok
 test('str'); // ok
 test(\'str\'); // ok

 
 Expected:

 str '' str
 str \'\' str

 str \'\' str
 str \'\' str

 'str'
 \'str\'

 \'str\'
 \'str\'

 
 Result:

 str '' str
 str \'' str

 str \'\' str
 str \'\' str

 'str'
 \'str\'

 \'str\'
 \'str\'


  Martin Scotta

 --
 PHP Internals - PHP Runtime Development Mailing List
 To unsubscribe, visit: http://www.php.net/unsub.php



Did no one see why the regex was wrong?

RegexBuddy (a windows app) explains regexes VERY VERY well.


-- 
Richard Quadling
Twitter : EE : Zend
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] preg_replace does not replace all occurrences

2011-03-15 Thread Richard Quadling
On 15 March 2011 10:32, Richard Quadling rquadl...@gmail.com wrote:
 On 14 March 2011 20:36, Hannes Landeholm landeh...@gmail.com wrote:
 What is more likely to be wrong? Your understanding of a specific
 regex pattern (which happens to be full of escapes making it
 incredibly hard to read) or the implementation of preg_replace?

 ~Hannes

 On 14 March 2011 16:18, Martin Scotta martinsco...@gmail.com wrote:

 I chose the simplest example to show the preg_replace behavior, there are
 better (and safer) ways to scape slash characters.
 Anyways, *is this the expected preg_replace behavior?*

  Martin

 ?php
 function test($str) {
    static $re = '/(^|[^])\'/';
    static $change = '$1\\\'';

    echo $str, PHP_EOL,
        preg_replace($re, $change, $str), PHP_EOL, PHP_EOL;
 }

 test(str '' str); // bug?
 test(str \\'\\' str); // ok
 test('str'); // ok
 test(\'str\'); // ok

 
 Expected:

 str '' str
 str \'\' str

 str \'\' str
 str \'\' str

 'str'
 \'str\'

 \'str\'
 \'str\'

 
 Result:

 str '' str
 str \'' str

 str \'\' str
 str \'\' str

 'str'
 \'str\'

 \'str\'
 \'str\'


  Martin Scotta

 --
 PHP Internals - PHP Runtime Development Mailing List
 To unsubscribe, visit: http://www.php.net/unsub.php



 Did no one see why the regex was wrong?

 RegexBuddy (a windows app) explains regexes VERY VERY well.

The important bit (where the problem lies with regard to the regex) is ...

Match a single character NOT present in the list below «[^]»
A \ character «\\»
A \ character «\\»


The issue is the word _single_.




-- 
Richard Quadling
Twitter : EE : Zend
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] SplFileObject Countable

2011-03-15 Thread Nick Pope

On 15/03/11 10:01, Peter Cowburn wrote:

For countBytes() how is that different from SplFileInfo's getSize() ?
As for countWords() and the others, I think this crosses the line (in
my view) over what a File Object should provide.


Hi Peter  Sebastian,

Bah.  It isn't.  Obviously that was going to exist already, but was 
thinking about methods looking like countX() too much :)


Perhaps you are right, Peter, on your opinions about what a file 
object should provide.  I would think, in that case, that a 
getLineCount() shouldn't exist on the file object either.


Currently we have:

SplFileInfo  -- information/metadata about a file.
 |
 V
   SplFileObject -- modify/access contents of a file.

It could make sense to subclass this to provide methods for accessing 
information about the contents of a file.  As for a name, I'm not sure 
what would be best, but perhaps something like SplFileData.  Maybe 
someone else can come up with a better name?


Then you could have the following methods:

getByteCount() -- the same as getSize(), but for here for consistency.
getCharCount()
getLineCount()
getWordCount()
getLongestLine()

Another consideration is how these should behave if we have a binary 
file - am not sure what GNU wc does, but perhaps that is a starting 
point for deciding what should happen.


Also thought might be given to what other useful methods could be 
provided for getting information about the contents of a file.  Some 
ideas (sensible or otherwise!):


getShortestLine()
getEolFormat()
setEolFormat() -- allow switching between LF, CR and CRLF.
getLineIndent() -- Could return '\t', '  ', '', etc.
setLineIndent()
hasEmptyLines()
hasTrailingWhiteSpace()
...

It may also make sense to cache the result while the file is not 
modified as some of these operations could be expensive.


Anyway - I'll stop rambling.  I think this would be better than just 
hacking in a method for the sake of it.


Cheers,

Nick

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] SplFileObject Countable

2011-03-15 Thread Alexey Zakhlestin
On Tue, Mar 15, 2011 at 1:54 PM, Nick Pope p...@nickpope.me.uk wrote:

 Currently we have:

    SplFileInfo  -- information/metadata about a file.
         |
         V
   SplFileObject -- modify/access contents of a file.

 It could make sense to subclass this to provide methods for accessing
 information about the contents of a file.  As for a name, I'm not sure what
 would be best, but perhaps something like SplFileData.  Maybe someone else
 can come up with a better name?

probably SplTextFileObject, as these methods make sense for text files


-- 
Alexey Zakhlestin, http://twitter.com/jimi_dini
http://www.milkfarmsoft.com/

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] preg_replace does not replace all occurrences

2011-03-15 Thread Ben Schmidt

static $re = '/(^|[^])\'/';


Did no one see why the regex was wrong?


I saw what the regex was. I didn't think like you that it was 'wrong'.

Once you unescape the characters in the PHP single-quoted string above
(where two backslashes count as one, and backslash-quote counts as a
quote), the actual pattern that reaches the preg_replace function is:

   /(^|[^\\])'/


RegexBuddy (a windows app) explains regexes VERY VERY well.


What kind of patterns? Does it support PCRE ones?


The important bit (where the problem lies with regard to the regex) is
...

Match a single character NOT present in the list below «[^]»
 A \ character «\\»
 A \ character «\\»


This is not the case.

1. As above, the pattern reaching preg_replace is /(^|[^\\])'/

2. PCRE, unlike many other regular expression implementations, allows
backslash-escaping inside character classes (square brackets). So the
doubled backslash only actually counts as a single backslash character
to be excluded from the set of characters the atom will match.

There is no error here. (And even if there were two backslashes being
excluded, of course, it wouldn't hurt anything or change the meaning of
the pattern.)


The issue is the word _single_.


I don't think anybody thought otherwise.

The problem was that, to a casual observer, the pattern seems to mean a
quote which doesn't already have a backslash before it. I believe this
was its intent. (And the replacement added the 'missing' backslash.)

But the pattern doesn't mean that. It actually means a character which
isn't a backslash, followed by a quote. This is subtly different.

And it's most noticeable when two quotes follow each other in the
subject string. In

   str''str

first the pattern matches r' (non-backslash followed by quote), and
then it keeps searching from that point, i.e. it searches 'str. Since
this isn't the beginning of the string, and there is no quote following
a non-backslash character, there are no further matches.

Now, here is a pattern which actually means a quote which doesn't
already have a backslash before it which is achieved by means of a
lookbehind assertion, which, even when searching the string after the
first match, 'str, still 'looks back' on the earlier part of the
string to recognise the second quote is not preceded by a backslash and
match a second time:

   /(^|(?!\\))'/

As a PHP single-quoted string this is:

   '/(^|(?!))\'/'

Hope this helps,

Ben.




--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] preg_replace does not replace all occurrences

2011-03-15 Thread Ben Schmidt

Now, here is a pattern which actually means a quote which doesn't
already have a backslash before it which is achieved by means of a
lookbehind assertion, which, even when searching the string after the
first match, 'str, still 'looks back' on the earlier part of the
string to recognise the second quote is not preceded by a backslash and
match a second time:

/(^|(?!\\))'/

As a PHP single-quoted string this is:

'/(^|(?!))\'/'


And I should mention, as Martin did, that this actually isn't a good
idea. There are better/safer ways to escape quotes. In particular,
consider how this subject string

   str\\'; delete from users;

will not have the quote escaped, because it is preceded by *two*
backslashes. To match more carefully, you have to be careful to 'eat
backslashes in pairs'. Someone gave a pattern that attempted to do
something like that in an earlier post, too.

Ben.




--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] preg_replace does not replace all occurrences

2011-03-15 Thread Dave Ingram
On 03/15/11 12:41, Ben Schmidt wrote:
 [snip]

 Hope this helps,

 Ben.

As an outsider in this discussion, I'd just like to applaud you for one
of the best, in-depth, most patient and most thorough explanations I
have ever seen on a mailing list.


Dave

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] preg_replace does not replace all occurrences

2011-03-15 Thread Richard Quadling
On 15 March 2011 12:41, Ben Schmidt mail_ben_schm...@yahoo.com.au wrote:
    static $re = '/(^|[^])\'/';

 Did no one see why the regex was wrong?

 I saw what the regex was. I didn't think like you that it was 'wrong'.

 Once you unescape the characters in the PHP single-quoted string above
 (where two backslashes count as one, and backslash-quote counts as a
 quote), the actual pattern that reaches the preg_replace function is:

   /(^|[^\\])'/

 RegexBuddy (a windows app) explains regexes VERY VERY well.

 What kind of patterns? Does it support PCRE ones?


Yep and MANY other flavours (C#,  C++,  Dephi, Groovy, Java,
Javascript, MySQL, ...)

 The important bit (where the problem lies with regard to the regex) is
 ...

 Match a single character NOT present in the list below «[^]»
         A \ character «\\»
         A \ character «\\»

 This is not the case.

 1. As above, the pattern reaching preg_replace is /(^|[^\\])'/

 2. PCRE, unlike many other regular expression implementations, allows
 backslash-escaping inside character classes (square brackets). So the
 doubled backslash only actually counts as a single backslash character
 to be excluded from the set of characters the atom will match.

 There is no error here. (And even if there were two backslashes being
 excluded, of course, it wouldn't hurt anything or change the meaning of
 the pattern.)

 The issue is the word _single_.

 I don't think anybody thought otherwise.

 The problem was that, to a casual observer, the pattern seems to mean a
 quote which doesn't already have a backslash before it. I believe this
 was its intent. (And the replacement added the 'missing' backslash.)

 But the pattern doesn't mean that. It actually means a character which
 isn't a backslash, followed by a quote. This is subtly different.

 And it's most noticeable when two quotes follow each other in the
 subject string. In

   str''str

 first the pattern matches r' (non-backslash followed by quote), and
 then it keeps searching from that point, i.e. it searches 'str. Since
 this isn't the beginning of the string, and there is no quote following
 a non-backslash character, there are no further matches.

 Now, here is a pattern which actually means a quote which doesn't
 already have a backslash before it which is achieved by means of a
 lookbehind assertion, which, even when searching the string after the
 first match, 'str, still 'looks back' on the earlier part of the
 string to recognise the second quote is not preceded by a backslash and
 match a second time:

   /(^|(?!\\))'/

 As a PHP single-quoted string this is:

   '/(^|(?!))\'/'

 Hope this helps,

 Ben.





If I say ...

?php
echo  '/(^|[^])\'/';
?

I get ...

/(^|[^\\])'/


which is explained as ...



(^|[^\\])'

Options: case insensitive; ^ and $ match at line breaks

Match the regular expression below and capture its match into
backreference number 1 «(^|[^\\])»
   Match either the regular expression below (attempting the next
alternative only if this one fails) «^»
  Assert position at the beginning of a line (at beginning of the
string or after a line break character) «^»
   Or match regular expression number 2 below (the entire group fails
if this one fails to match) «[^\\]»
  Match any character that is NOT a \ character «[^\\]»
Match the character “'” literally «'»

And that certainly makes a LOT more sense.

Decoding regexes and handling the escaping needed for the language is
a real headache sometimes.

Just imagine creating regex code for use by client side Javascript using PHP.

8 \ in a row for a single \ wouldn't be impossible.

Sorry for the confusion.


-- 
Richard Quadling
Twitter : EE : Zend
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-DEV] Package php binaries + php script into one single executable file

2011-03-15 Thread Olivier Hoareau
Hi !

I would like to be able to distribute (freely) a single executable
(binary) containing :

- php binaries (v 5.3+)
- a php script already packaged as a .phar (1 Mb, requiring PHP 5.3+)
- additional (optional) compiled extensions
- php.ini
- all other resources required by the php executable to run

The aim is to be able to provide a command line tool based on PHP but not
requiring my user to install PHP *before* using the tool (and only download
the tool as a single executable file to execute it)
I would like my users to be able to use this packaged tool (requiring PHP
5.3+) whatever version of PHP my users have already installed (or not) on
their system.

Targeted platforms are :

- windows (XP / Vista / 7) = 70% of my users
- linux debian-like (ubuntu / debian) = 20% of my users
- other platforms = 10% of my users

At this point, this is not a problem for me to have a huge self-executable
file ( 10Mb).
I need to be able to package a version of the tool using a batch (or
script), as I am using continuous integration.

Do you have ideas on how to reach this goal ?
The tool is open source, using New BSD License (currently, in beta version).

Thanks for your answers !

Best regards,

Olivier Hoareau


[PHP-DEV] Re: Package php binaries + php script into one single executable file

2011-03-15 Thread Alec

I am also interested in hearing the answer to this.

Alec Gorge

On 3/15/2011 4:09 PM, Olivier Hoareau wrote:

Hi !

I would like to be able to distribute (freely) a single executable
(binary) containing :

- php binaries (v 5.3+)
- a php script already packaged as a .phar (1 Mb, requiring PHP 5.3+)
- additional (optional) compiled extensions
- php.ini
- all other resources required by the php executable to run

The aim is to be able to provide a command line tool based on PHP but not
requiring my user to install PHP *before* using the tool (and only download
the tool as a single executable file to execute it)
I would like my users to be able to use this packaged tool (requiring PHP
5.3+) whatever version of PHP my users have already installed (or not) on
their system.

Targeted platforms are :

- windows (XP / Vista / 7) =  70% of my users
- linux debian-like (ubuntu / debian) =  20% of my users
- other platforms =  10% of my users

At this point, this is not a problem for me to have a huge self-executable
file (  10Mb).
I need to be able to package a version of the tool using a batch (or
script), as I am using continuous integration.

Do you have ideas on how to reach this goal ?
The tool is open source, using New BSD License (currently, in beta version).

Thanks for your answers !

Best regards,

Olivier Hoareau




--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] Package php binaries + php script into one single executable file

2011-03-15 Thread James Butler
Hi Olivier,

Could you be a little more specific about what questions you have? Is it to do 
with the licensing or physically how to go about achieving your aim?

Regards,
James

--
James Butler
Sent from my iPhone

On 15 Mar 2011, at 20:02, Olivier Hoareau oliv...@phppro.fr wrote:

 Hi !
 
 I would like to be able to distribute (freely) a single executable
 (binary) containing :
 
 - php binaries (v 5.3+)
 - a php script already packaged as a .phar (1 Mb, requiring PHP 5.3+)
 - additional (optional) compiled extensions
 - php.ini
 - all other resources required by the php executable to run
 
 The aim is to be able to provide a command line tool based on PHP but not
 requiring my user to install PHP *before* using the tool (and only download
 the tool as a single executable file to execute it)
 I would like my users to be able to use this packaged tool (requiring PHP
 5.3+) whatever version of PHP my users have already installed (or not) on
 their system.
 
 Targeted platforms are :
 
 - windows (XP / Vista / 7) = 70% of my users
 - linux debian-like (ubuntu / debian) = 20% of my users
 - other platforms = 10% of my users
 
 At this point, this is not a problem for me to have a huge self-executable
 file ( 10Mb).
 I need to be able to package a version of the tool using a batch (or
 script), as I am using continuous integration.
 
 Do you have ideas on how to reach this goal ?
 The tool is open source, using New BSD License (currently, in beta version).
 
 Thanks for your answers !
 
 Best regards,
 
 Olivier Hoareau


--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] Package php binaries + php script into one single executable file

2011-03-15 Thread Olivier Hoareau

 Hi Olivier,


Hi !


 Could you be a little more specific about what questions you have? Is it to
 do with the licensing or physically how to go about achieving your aim?


technical point : how to go about achieving my aim ;)

Ideas :

- specific compilation of PHP (I am newbee, but there are lots of expert on
this list I think ;))
- others ?

This is not (I think ?) a problem with license, my current targeted license
is BSD-style (New BSD by defaults, but I can move if necessary).

Thanks !



 Regards,
 James

 --
 James Butler
 Sent from my iPhone

 On 15 Mar 2011, at 20:02, Olivier Hoareau oliv...@phppro.fr wrote:

  Hi !
 
  I would like to be able to distribute (freely) a single executable
  (binary) containing :
 
  - php binaries (v 5.3+)
  - a php script already packaged as a .phar (1 Mb, requiring PHP 5.3+)
  - additional (optional) compiled extensions
  - php.ini
  - all other resources required by the php executable to run
 
  The aim is to be able to provide a command line tool based on PHP but not
  requiring my user to install PHP *before* using the tool (and only
 download
  the tool as a single executable file to execute it)
  I would like my users to be able to use this packaged tool (requiring
 PHP
  5.3+) whatever version of PHP my users have already installed (or not) on
  their system.
 
  Targeted platforms are :
 
  - windows (XP / Vista / 7) = 70% of my users
  - linux debian-like (ubuntu / debian) = 20% of my users
  - other platforms = 10% of my users
 
  At this point, this is not a problem for me to have a huge
 self-executable
  file ( 10Mb).
  I need to be able to package a version of the tool using a batch (or
  script), as I am using continuous integration.
 
  Do you have ideas on how to reach this goal ?
  The tool is open source, using New BSD License (currently, in beta
 version).
 
  Thanks for your answers !
 
  Best regards,
 
  Olivier Hoareau




-- 
Olivier Hoareau
Consultant Expert PHP / Coach Méthodologie Agile

PHPPRO
www.phppro.fr
Visitez le blog http://blog.phppro.fr !


Re: [PHP-DEV] Package php binaries + php script into one single executable file

2011-03-15 Thread Tomas Kuliavas
2011.03.15 22:09 Olivier Hoareau rašė:
 Hi !

 I would like to be able to distribute (freely) a single executable
 (binary) containing :

 - php binaries (v 5.3+)
 - a php script already packaged as a .phar (1 Mb, requiring PHP 5.3+)
 - additional (optional) compiled extensions
 - php.ini
 - all other resources required by the php executable to run

 The aim is to be able to provide a command line tool based on PHP but not
 requiring my user to install PHP *before* using the tool (and only
 download
 the tool as a single executable file to execute it)
 I would like my users to be able to use this packaged tool (requiring
 PHP
 5.3+) whatever version of PHP my users have already installed (or not) on
 their system.

 Targeted platforms are :

 - windows (XP / Vista / 7) = 70% of my users
 - linux debian-like (ubuntu / debian) = 20% of my users
 - other platforms = 10% of my users

 At this point, this is not a problem for me to have a huge self-executable
 file ( 10Mb).
 I need to be able to package a version of the tool using a batch (or
 script), as I am using continuous integration.

 Do you have ideas on how to reach this goal ?
 The tool is open source, using New BSD License (currently, in beta
 version).

Create .deb package and make it dependent on PHP for Debian/Ubuntu. Debian
has docs and tools that allow to do that. PHP is in standard Debian/Ubuntu
software repository.

Distribute .phar package alone for users who already have PHP. List PHP
extensions your package depends on.

Create automated installer for Windows which downloads PHP from the
network. See microsoft web platform installer for more ideas.

IMHO your package license is not compatible with PHP license. You can't
distribute PHP with BSD license.


-- 
Tomas



-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] Package php binaries + php script into one single executable file

2011-03-15 Thread Olivier Hoareau
Hi Tomas !

Thanks for your proposals.


 Create .deb package and make it dependent on PHP for Debian/Ubuntu. Debian
 has docs and tools that allow to do that. PHP is in standard Debian/Ubuntu
 software repository.


This solution does not provide me one of the goal I need to reach : that my
users be able to use the tool even if they already have PHP installed on
their system but with a version not compatible with the tool.
Let me explain why : the goal of the tool is to provide command line actions
for team (dev team) members, such as the ones (but not only) provided by
tools like zf / sf / maven (but not sticked to a specific framework and
working with all frameworks), so the targeted users are already using PHP
but with specific version of PHP (depending on the need for the application
they are currently developing). I would like to be able to provide all the
features my tool provide to those teams BUT without the need for these team
to upgrade the version of PHP they are using on their desktop (mostly PHP
5.2)


 Distribute .phar package alone for users who already have PHP. List PHP
 extensions your package depends on.


This solution is already in use, but not perfect, for the problem I
described above, at least, because a small percentage of my targetted users
(at this moment) are using PHP 5.3+


 Create automated installer for Windows which downloads PHP from the
 network. See microsoft web platform installer for more ideas.


This is a possible solution if installing PHP in a custom directory without
system-wide installation and if 2 version of PHP can coexist on the same
filesystem without conflicts on extensions/php.ini/system variables, do you
have links ? (I will google it)

IMHO your package license is not compatible with PHP license. You can't
 distribute PHP with BSD license.


OK, I was not aware of this limitation.
It is not a problem to modify the license of the tool to one that is
compatible with PHP license, my purpose is to share something, not to sell
it. Do you (are others) have advice on this specific points ?

Thanks !

Olivier H.




 --
 Tomas



 --
 PHP Internals - PHP Runtime Development Mailing List
 To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP-DEV] Package php binaries + php script into one single executable file

2011-03-15 Thread Olivier Hoareau
Found one interesting tool named PHPACK :
http://winbinder.org/forum/viewtopic.php?f=8t=1148 (windows only)

http://winbinder.org/forum/viewtopic.php?f=8t=1148Tool is no more
supported (ended mid-2010), but seems to be working with PHP 5.3.

What it does : package php5ts.dll + custom php scripts into one .exe
(windows only).

Tested with my phar file generated a 3Mb exe file (not that big).

But limited support for extension (few statically linked extension).

I have not yet tested the exe file on a blank box (i.e. where php not
already installed).

Seems to be an interesting solution for my windows users.

Other ideas ?

oha

2011/3/15 Olivier Hoareau oliv...@phppro.fr

 Hi Tomas !

 Thanks for your proposals.


 Create .deb package and make it dependent on PHP for Debian/Ubuntu. Debian
 has docs and tools that allow to do that. PHP is in standard Debian/Ubuntu
 software repository.


 This solution does not provide me one of the goal I need to reach : that my
 users be able to use the tool even if they already have PHP installed on
 their system but with a version not compatible with the tool.
 Let me explain why : the goal of the tool is to provide command line
 actions for team (dev team) members, such as the ones (but not only)
 provided by tools like zf / sf / maven (but not sticked to a specific
 framework and working with all frameworks), so the targeted users are
 already using PHP but with specific version of PHP (depending on the need
 for the application they are currently developing). I would like to be able
 to provide all the features my tool provide to those teams BUT without the
 need for these team to upgrade the version of PHP they are using on their
 desktop (mostly PHP 5.2)


 Distribute .phar package alone for users who already have PHP. List PHP
 extensions your package depends on.


 This solution is already in use, but not perfect, for the problem I
 described above, at least, because a small percentage of my targetted users
 (at this moment) are using PHP 5.3+


 Create automated installer for Windows which downloads PHP from the
 network. See microsoft web platform installer for more ideas.


 This is a possible solution if installing PHP in a custom directory without
 system-wide installation and if 2 version of PHP can coexist on the same
 filesystem without conflicts on extensions/php.ini/system variables, do you
 have links ? (I will google it)

 IMHO your package license is not compatible with PHP license. You can't
 distribute PHP with BSD license.


 OK, I was not aware of this limitation.
 It is not a problem to modify the license of the tool to one that is
 compatible with PHP license, my purpose is to share something, not to sell
 it. Do you (are others) have advice on this specific points ?

 Thanks !

 Olivier H.




 --

 Tomas



 --
 PHP Internals - PHP Runtime Development Mailing List
 To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP-DEV] Package php binaries + php script into one singleexecutable file

2011-03-15 Thread Alec
I actually wrote that. I never imagined someone would actually find that 
useful!


If you don't mind having a few external dlls, you can use dl (ick!) to 
load the extensions.


I gave up supporting that because compiling the custom lightweight stubs 
took more work than I cared for. I am considering reviving the project 
and this time not writing in PHP (PHP should really not be used for GUIs 
IMO).


If you can wait a bit. I can setup my code (Visual C++ projects mostly) 
on GitHub so you can clone and compile whatever stubs you want.


If you cannot wait, or want to tinker, here is a thread I wrote that 
talks about making a static/stub exe:


http://winbinder.org/forum/viewtopic.php?f=10t=1178

Good luck!

Alec Gorge

On 3/15/2011 7:40 PM, Olivier Hoareau wrote:

Found one interesting tool named PHPACK :
http://winbinder.org/forum/viewtopic.php?f=8t=1148 (windows only)

http://winbinder.org/forum/viewtopic.php?f=8t=1148Tool is no more
supported (ended mid-2010), but seems to be working with PHP 5.3.

What it does : package php5ts.dll + custom php scripts into one .exe
(windows only).

Tested with my phar file generated a 3Mb exe file (not that big).

But limited support for extension (few statically linked extension).

I have not yet tested the exe file on a blank box (i.e. where php not
already installed).

Seems to be an interesting solution for my windows users.

Other ideas ?

oha

2011/3/15 Olivier Hoareauoliv...@phppro.fr


Hi Tomas !

Thanks for your proposals.



Create .deb package and make it dependent on PHP for Debian/Ubuntu. Debian
has docs and tools that allow to do that. PHP is in standard Debian/Ubuntu
software repository.



This solution does not provide me one of the goal I need to reach : that my
users be able to use the tool even if they already have PHP installed on
their system but with a version not compatible with the tool.
Let me explain why : the goal of the tool is to provide command line
actions for team (dev team) members, such as the ones (but not only)
provided by tools like zf / sf / maven (but not sticked to a specific
framework and working with all frameworks), so the targeted users are
already using PHP but with specific version of PHP (depending on the need
for the application they are currently developing). I would like to be able
to provide all the features my tool provide to those teams BUT without the
need for these team to upgrade the version of PHP they are using on their
desktop (mostly PHP 5.2)



Distribute .phar package alone for users who already have PHP. List PHP
extensions your package depends on.



This solution is already in use, but not perfect, for the problem I
described above, at least, because a small percentage of my targetted users
(at this moment) are using PHP 5.3+



Create automated installer for Windows which downloads PHP from the
network. See microsoft web platform installer for more ideas.



This is a possible solution if installing PHP in a custom directory without
system-wide installation and if 2 version of PHP can coexist on the same
filesystem without conflicts on extensions/php.ini/system variables, do you
have links ? (I will google it)

IMHO your package license is not compatible with PHP license. You can't

distribute PHP with BSD license.



OK, I was not aware of this limitation.
It is not a problem to modify the license of the tool to one that is
compatible with PHP license, my purpose is to share something, not to sell
it. Do you (are others) have advice on this specific points ?

Thanks !

Olivier H.





--

Tomas



--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php







--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-DEV] [patch] Session RSHUTDOWN, shutdown_destructors() issues

2011-03-15 Thread Tim Starling
This is a followup to http://bugs.php.net/bug.php?id=54157 . Johannes
said I should post here.

In the course of my MediaWiki development work, I hit a strange issue
involving session_set_save_handler().

PHP's built-in session handler is pretty much useless when you have
more than one server serving a given site, so
session_set_save_handler() is essential. MediaWiki has a feature
allowing it to save sessions via its memcached client. A suitable
client object is put in $wgMemc during setup, which is used when the
session is closed. A minor change to the way this variable was
initialised caused it to disappear from the global symbol table before
the session save handler was called.

This turned out to be due to a broken algorithm in
shutdown_destructors() in zend_execute_API.c. The algorithm basically
does this:

1. Delete all objects from the global symbol table which have a zval
reference count of 1
2. If any objects were deleted, go to step 1.

Obviously the intention is to first delete the references, and then to
delete the objects which were referred to. It doesn't work that way:
if you have a reference, both symbol table entries point to the same
zval, so they both have a reference count of 2, so the algorithm skips
both and leaves them intact for RSHUTDOWN. My $wgMemc initialisation
change caused the reference count to drop from 2 to 1, so the variable
was deleted.

Fixing this function to correctly delete all objects from the global
symbol table would be easy enough (against 5.3):

http://tstarling.com/stuff/shutdown_destructors-sanity.patch

But please don't apply that, because it would break all released
versions of MediaWiki.

We now come to the next strange thing about this code: why is it
attempting to delete all objects from the global symbol table anyway?
There are plenty of other ways to store objects: function static
variables, class static variables, etc. Deleting them from $GLOBALS
doesn't stop them from being accessed. And besides, we know that
there's no problem with accessing an object after __destruct() has
been called on it, because that was the whole point of splitting out
shutdown_destructors() in the first place, as a comment in
shutdown_executor() explains:

/* Removed because this can not be safely done, e.g. in this situation:
   Object 1 creates object 2
   Object 3 holds reference to object 2.
   Now when 1 and 2 are destroyed, 3 can still access 2 in its
destructor, with
   very problematic results */
/* zend_objects_store_call_destructors(EG(objects_store)
TSRMLS_CC); */

Just removing the whole loop would suit me, as a 5.3.x stopgap measure:

http://tstarling.com/stuff/no-global-deletion.patch

But that still leaves the problem that the session save handler is
called in the strange and scary world of half-shut-down PHP. We don't
know what RSHUTDOWN functions have been called before the session
RSHUTDOWN, so we don't know what userspace code will work and what
won't. A workaround is easy enough:

http://www.mediawiki.org/wiki/Special:Code/MediaWiki/83147

but I thought I would be a good open source citizen and come up with a
proper solution, against trunk. It is attached and at:

http://tstarling.com/stuff/session-pre-deactivate.patch

The idea is to introduce a pre-RSHUTDOWN hook, allowing modules to
call user code in a relatively sane environment. It's implemented in a
way that is closely analogous to the post-deactivate hook. I had
trouble testing it because trunk was so broken that it wouldn't run
MediaWiki, but the patch appears to work for simple CLI test cases.

-- Tim Starling
Index: ext/session/session.c
===
--- ext/session/session.c	(revision 309263)
+++ ext/session/session.c	(working copy)
@@ -1953,6 +1953,13 @@
 }
 /* }}} */
 
+static ZEND_MODULE_PRE_DEACTIVATE_D(session) /* {{{ */
+{
+	php_session_flush(TSRMLS_C);
+	return SUCCESS;
+}
+/* }}} */
+
 static PHP_RSHUTDOWN_FUNCTION(session) /* {{{ */
 {
 	int i;
@@ -2373,7 +2380,8 @@
 	PHP_GINIT(ps),
 	NULL,
 	NULL,
-	STANDARD_MODULE_PROPERTIES_EX
+	ZEND_MODULE_PRE_DEACTIVATE_N(session),
+	STANDARD_MODULE_PROPERTIES_EX2
 };
 
 #ifdef COMPILE_DL_SESSION
Index: Zend/zend.h
===
--- Zend/zend.h	(revision 309263)
+++ Zend/zend.h	(working copy)
@@ -645,6 +645,7 @@
 void zend_call_destructors(TSRMLS_D);
 void zend_activate_modules(TSRMLS_D);
 void zend_deactivate_modules(TSRMLS_D);
+void zend_pre_deactivate_modules(TSRMLS_D);
 void zend_post_deactivate_modules(TSRMLS_D);
 
 #if ZEND_DEBUG
Index: Zend/zend_modules.h
===
--- Zend/zend_modules.h	(revision 309263)
+++ Zend/zend_modules.h	(working copy)
@@ -33,7 +33,7 @@
 #define ZEND_MODULE_INFO_FUNC_ARGS zend_module_entry *zend_module TSRMLS_DC
 #define ZEND_MODULE_INFO_FUNC_ARGS_PASSTHRU zend_module TSRMLS_CC
 
-#define ZEND_MODULE_API_NO 20100525
+#define ZEND_MODULE_API_NO