Re: [PHP-DEV] mysqli_fetch_field() mysqlnd libmysql differences

2012-02-21 Thread Johannes Schlüter
On Fri, 2012-02-17 at 08:38 -0500, Daniel Convissor wrote:
  A related problem was found by the test script.  libmysql is completely
  ignoring the character set information in my.cnf.  Plus, if one forces a
  character set by calling options(SET NAMES utf8) before connecting,
  character_set_name() still returns unexpected information.
  
  Can you please take a look at this test script:
  http://www.analysisandsolutions.com/php/libmysql.ignoring.character.set.php
 
 Can one of you please examine why libmysql is not acting as documented
 and reply here in the near future?

In my tests it worked like I expect:
- the initial charset is the one configured
- changing the charset affects the behavior

Mind two things:

1) You said

 * /etc/my.cnf settings are (no other my.cnf files exist):
 * + default-character-set = utf8
 * + character-set-server = utf8

In which section of the my.cnf file? Both for the server, or for the
client?

2) SET NAMES changes the setting on the server. The client won't know
about this and still assume the old charset was used. Use
mysqli_set_charset().

In summary: charsets and encoding are a mess, especially if you have
many places to configure those. One small oversight and all is messed.

As reference:
http://dev.mysql.com/doc/refman/5.5/en/charset-configuration.html

johannes

 Thanks,
 
 --Dan
 
 -- 
  T H E   A N A L Y S I S   A N D   S O L U T I O N S   C O M P A N Y
 data intensive web and database programming
 http://www.AnalysisAndSolutions.com/
  4015 7th Ave #4, Brooklyn NY 11232  v: 718-854-0335 f: 718-854-0409
 



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



[PHP-DEV] file_get_contents from HTTPS on Slackware 13.1

2012-02-21 Thread Bostjan Skufca
Hi all,

we've bumped into a possible bug where file_get_contents() returns empty
string if we try to get contents from HTTPS source. This error only occurs
if PHP is compiled with --with-curlwrappers.

Funny thing is this only happens on slackware 13.1, but not on 13.0 or
older. I've checked ./configure and make output and they are almost
identical, strace does not return anything meaningful.
Environment is highly controlled by configuration management, software is
built in the same way, except underlying OS versions (and very basic libs
and tools versions) differ.

Two questions:
1. Do any of you guys have any idea about this?
2. How to continue exploring deeper to discover what actually this error is
all about?

Regards,
b.


Re: [PHP-DEV] file_get_contents from HTTPS on Slackware 13.1

2012-02-21 Thread Ángel González
On 21/02/12 15:54, Bostjan Skufca wrote:
 Hi all,

 we've bumped into a possible bug where file_get_contents() returns empty
 string if we try to get contents from HTTPS source. This error only occurs
 if PHP is compiled with --with-curlwrappers.

 Funny thing is this only happens on slackware 13.1, but not on 13.0 or
 older. I've checked ./configure and make output and they are almost
 identical, strace does not return anything meaningful.
 Environment is highly controlled by configuration management, software is
 built in the same way, except underlying OS versions (and very basic libs
 and tools versions) differ.

 Two questions:
 1. Do any of you guys have any idea about this?
 2. How to continue exploring deeper to discover what actually this error is
 all about?

 Regards,
 b.
Have you checked it's not a failure verificating the certificate?


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



[PHP-DEV] Exceptions for method on non-object rather than fatal (desired feature?)

2012-02-21 Thread Ralf Lang

Hi list,

I am aware this question might have been discussed to death but I did 
some googling on $subject and watched the bug/feature tracker and it 
seems most entries on this issue are old and unanswered.


Is there a design decision or hard-to-overcome engine limitation which 
prevents turning method-on-nonobject into a catchable Exception? Or did 
just nobody step up and provide a patch?


Rationale:

In another language/framework context I did a lot of chained/nested 
stuff like this:


$granny_name = $baby-getMother()-getMother()-getName();

In PHP I would rather do

$mother = $baby-getMother();

if ($mother) {
$granny = $mother-getMother();
if ($granny) {
$granny_name  = $granny-getName();
}
}

because I have no way to catch if $mother or $granny cannot be retrieved.

If it's generally welcome I'll try and supply a patch.

(Now let's hope this doesn't start something evil.)

--
Ralf Lang
Linux Consultant / Developer
Mail: l...@b1-systems.de

B1 Systems GmbH
Osterfeldstraße 7 / 85088 Vohburg / http://www.b1-systems.de
GF: Ralph Dehner / Unternehmenssitz: Vohburg / AG: Ingolstadt,HRB 3537

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



Re: [PHP-DEV] Exceptions for method on non-object rather than fatal (desired feature?)

2012-02-21 Thread Ralf Lang

Am 21.02.2012 16:55, schrieb Martin Amps:

Could you not implement such functionality within your class as follows:

class Family {
public function getMother() {
if ($this-hasMother())
return $someObj;
else
throw new BadMethodCallException(...);
}
}

try {
$granny_name = $baby-getMother()-getMother()-getName();
} catch (BadMethodCallException $ex) {

}

Martin


Hi Martin,

First of all, thank you for your rapid response but it doesn't address 
my question (or at least the question I intended to ask)


of course there is always a way to script around issues rather than 
adressing them. I just want to know if the change would be desired. I 
have code around which does exactly this, check on all levels of all 
possible combinations. Semantically, this is nonsense and it bloats the 
code. It's just a requirement because currently PHP handles this as 
non-recoverable fatal.


I see no reason why it would be not desirable to have PHP raise the 
exception rather than putting more or less repeating code snippets all 
around the place. That is why I am asking.



--
Ralf Lang
Linux Consultant / Developer
Tel.: +49-170-6381563
Mail: l...@b1-systems.de

B1 Systems GmbH
Osterfeldstraße 7 / 85088 Vohburg / http://www.b1-systems.de
GF: Ralph Dehner / Unternehmenssitz: Vohburg / AG: Ingolstadt,HRB 3537

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



Re: [PHP-DEV] Exceptions for method on non-object rather than fatal (desired feature?)

2012-02-21 Thread Kalle Sommer Nielsen
Hi Ralk

2012/2/21 Ralf Lang l...@b1-systems.de:
 Am 21.02.2012 16:55, schrieb Martin Amps:
 of course there is always a way to script around issues rather than
 adressing them. I just want to know if the change would be desired. I have
 code around which does exactly this, check on all levels of all possible
 combinations. Semantically, this is nonsense and it bloats the code. It's
 just a requirement because currently PHP handles this as non-recoverable
 fatal.

 I see no reason why it would be not desirable to have PHP raise the
 exception rather than putting more or less repeating code snippets all
 around the place. That is why I am asking.

This topic have been raised many many times (Turning errors into
Exceptions). What it seems like you are trying to shave off, is 3
lines, I do know that it is sample code but like Martin replied, you
should implement such yourself as PHP does not do any magical
overloading without explicitly declared, witch I think is a good
decision.

TL;DR, in basic terms, if you want it as a one-liner, you must
implement the overloading methods yourself to obtain that chaning you
are after.

-- 
regards,

Kalle Sommer Nielsen
ka...@php.net

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



Re: [PHP-DEV] Exceptions for method on non-object rather than fatal (desired feature?)

2012-02-21 Thread Ralf Lang

I see no reason why it would be not desirable to have PHP raise the
exception rather than putting more or less repeating code snippets all
around the place. That is why I am asking.


This topic have been raised many many times (Turning errors into
Exceptions).


What's the result? Should we do it or not?


as PHP does not do any magical
overloading without explicitly declared, witch I think is a good
decision.


No magic wanted here. Just a yes, want / no, don't want.


--
Ralf Lang
Linux Consultant / Developer
Tel.: +49-170-6381563
Mail: l...@b1-systems.de

B1 Systems GmbH
Osterfeldstraße 7 / 85088 Vohburg / http://www.b1-systems.de
GF: Ralph Dehner / Unternehmenssitz: Vohburg / AG: Ingolstadt,HRB 3537

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



Re: [PHP-DEV] file_get_contents from HTTPS on Slackware 13.1

2012-02-21 Thread Rasmus Lerdorf
On 02/21/2012 06:54 AM, Bostjan Skufca wrote:
 Hi all,
 
 we've bumped into a possible bug where file_get_contents() returns empty
 string if we try to get contents from HTTPS source. This error only occurs
 if PHP is compiled with --with-curlwrappers.
 
 Funny thing is this only happens on slackware 13.1, but not on 13.0 or
 older. I've checked ./configure and make output and they are almost
 identical, strace does not return anything meaningful.
 Environment is highly controlled by configuration management, software is
 built in the same way, except underlying OS versions (and very basic libs
 and tools versions) differ.
 
 Two questions:
 1. Do any of you guys have any idea about this?
 2. How to continue exploring deeper to discover what actually this error is
 all about?

Does a command line curl call to the same SSL URL work?

-Rasmus

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



Re: [PHP-DEV] Exceptions for method on non-object rather than fatal (desired feature?)

2012-02-21 Thread Kalle Sommer Nielsen
2012/2/21 Ralf Lang l...@b1-systems.de:
 I see no reason why it would be not desirable to have PHP raise the
 exception rather than putting more or less repeating code snippets all
 around the place. That is why I am asking.


 This topic have been raised many many times (Turning errors into
 Exceptions).


 What's the result? Should we do it or not?

It was a clear no from most core guys, if you want some more detailed
answer, try search the internals@ archieve on markmail.


 No magic wanted here. Just a yes, want / no, don't want.


What I suggest you to do, if you want this in the core, then write an
RFC[1], and propose your suggestion for it to get voted on.


[1] http://wiki.php.net/rfc

-- 
regards,

Kalle Sommer Nielsen
ka...@php.net

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



Re: [PHP-DEV] Exceptions for method on non-object rather than fatal (desired feature?)

2012-02-21 Thread Ángel González
On 21/02/12 17:06, Ralf Lang wrote:
 Am 21.02.2012 16:55, schrieb Martin Amps:
 Could you not implement such functionality within your class as follows:

 class Family {
 public function getMother() {
 if ($this-hasMother())
 return $someObj;
 else
 throw new BadMethodCallException(...);
 }
 }

 try {
 $granny_name = $baby-getMother()-getMother()-getName();
 } catch (BadMethodCallException $ex) {

 }

 Martin

 Hi Martin,

 First of all, thank you for your rapid response but it doesn't address
 my question (or at least the question I intended to ask)

 of course there is always a way to script around issues rather than
 adressing them. I just want to know if the change would be desired. I
 have code around which does exactly this, check on all levels of all
 possible combinations. Semantically, this is nonsense and it bloats
 the code. It's just a requirement because currently PHP handles this
 as non-recoverable fatal.

 I see no reason why it would be not desirable to have PHP raise the
 exception rather than putting more or less repeating code snippets all
 around the place. That is why I am asking.

You must be returning false/null somewhere. It's the same effor to
instead throw an exception or to return a Ghost family member.



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



Re: [PHP-DEV] Exceptions for method on non-object rather than fatal (desired feature?)

2012-02-21 Thread Ralf Lang

I see no reason why it would be not desirable to have PHP raise the
exception rather than putting more or less repeating code snippets all
around the place. That is why I am asking.


You must be returning false/null somewhere. It's the same effor to
instead throw an exception or to return a Ghost family member.


The $baby-mother() method cannot know if the using code just wants to 
collect the $mother object or execute code on it. It can also not know 
if having no $mother is a problem or just a fact to deal with. 
Unconditionally raising an exception is a bit overkill here, at least if 
we would get an exception for trying to access (null)-mother();


Currently the user code must check each link of the chain if it is 
available, although it is only interested if it can get the final result 
or not.


I'll follow the suggestion and write an RFC.

--
Ralf Lang
Linux Consultant / Developer
Tel.: +49-170-6381563
Mail: l...@b1-systems.de

B1 Systems GmbH
Osterfeldstraße 7 / 85088 Vohburg / http://www.b1-systems.de
GF: Ralph Dehner / Unternehmenssitz: Vohburg / AG: Ingolstadt,HRB 3537

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



Re: [PHP-DEV] Exceptions for method on non-object rather than fatal (desired feature?)

2012-02-21 Thread Ángel González
On 21/02/12 19:03, Ralf Lang wrote:
 I see no reason why it would be not desirable to have PHP raise the
 exception rather than putting more or less repeating code snippets all
 around the place. That is why I am asking.

 You must be returning false/null somewhere. It's the same effort to
 instead throw an exception or to return a Ghost family member.

 The $baby-mother() method cannot know if the using code just wants to
 collect the $mother object or execute code on it. It can also not know
 if having no $mother is a problem or just a fact to deal with.
 Unconditionally raising an exception is a bit overkill here, at least
 if we would get an exception for trying to access (null)-mother();

 Currently the user code must check each link of the chain if it is
 available, although it is only interested if it can get the final
 result or not.

 I'll follow the suggestion and write an RFC.
return new NoMother;





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



Re: [PHP-DEV] file_get_contents from HTTPS on Slackware 13.1

2012-02-21 Thread Bostjan Skufca
Weird. Curl is consistent. It does not work (in this case) without -k
(--insecure) option or explicitly setting ca-bundle on all OS versions.

Thanks for pointers, will remove --with-curlwrappers (marked experimental)
from my PHP configure line.

BTW what is the plan with --with-curlwrappers?
Will this eventually replace current stream code as default wrapper for
communication over the net?

Thanks,
b.



On 21 February 2012 18:16, Rasmus Lerdorf ras...@lerdorf.com wrote:

 On 02/21/2012 06:54 AM, Bostjan Skufca wrote:
  Hi all,
 
  we've bumped into a possible bug where file_get_contents() returns empty
  string if we try to get contents from HTTPS source. This error only
 occurs
  if PHP is compiled with --with-curlwrappers.
 
  Funny thing is this only happens on slackware 13.1, but not on 13.0 or
  older. I've checked ./configure and make output and they are almost
  identical, strace does not return anything meaningful.
  Environment is highly controlled by configuration management, software is
  built in the same way, except underlying OS versions (and very basic libs
  and tools versions) differ.
 
  Two questions:
  1. Do any of you guys have any idea about this?
  2. How to continue exploring deeper to discover what actually this error
 is
  all about?

 Does a command line curl call to the same SSL URL work?

 -Rasmus



Re: [PHP-DEV] Exceptions for method on non-object rather than fatal (desired feature?)

2012-02-21 Thread Tjerk Meesters
On 22 Feb, 2012, at 2:03 AM, Ralf Lang l...@b1-systems.de wrote:

 I see no reason why it would be not desirable to have PHP raise the
 exception rather than putting more or less repeating code snippets all
 around the place. That is why I am asking.
 
 You must be returning false/null somewhere. It's the same effor to
 instead throw an exception or to return a Ghost family member.
 
 The $baby-mother() method cannot know if the using code just wants to 
 collect the $mother object or execute code on it. It can also not know if 
 having no $mother is a problem or just a fact to deal with. Unconditionally 
 raising an exception is a bit overkill here, at least if we would get an 
 exception for trying to access (null)-mother();
 
 Currently the user code must check each link of the chain if it is available, 
 although it is only interested if it can get the final result or not.
 
 I'll follow the suggestion and write an RFC.
 

You'll have my vote! :) bloating code with chainable checks is just crazy, 
something that the engine can do much more efficiently and unambiguously. 


 -- 
 Ralf Lang
 Linux Consultant / Developer
 Tel.: +49-170-6381563
 Mail: l...@b1-systems.de
 
 B1 Systems GmbH
 Osterfeldstraße 7 / 85088 Vohburg / http://www.b1-systems.de
 GF: Ralph Dehner / Unternehmenssitz: Vohburg / AG: Ingolstadt,HRB 3537
 
 -- 
 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] Re: Exceptions for method on non-object rather than fatal (desired feature?)

2012-02-21 Thread Flavius Aspra

On 02/21/2012 03:18 PM, Ralf Lang wrote:


In PHP I would rather do

$mother = $baby-getMother();

if ($mother) {
  $granny = $mother-getMother();
  if ($granny) {
  $granny_name  = $granny-getName();
  }
}

because I have no way to catch if $mother or $granny cannot be retrieved.



There is a way:


 1  ?php
 2  class NonCallable {
 3  public function __call($meth, $args) {
 4  throw new Exception($meth does not exist);
 5  }
 6  }
 7  
 8  class Foo {
 9  protected $bar;
10  public function __construct($bar=NULL) {
11  $this-bar = $bar;
12  }
13  public function bar() {
14  if($this-bar) {
15  return $this;
16  }
17  return new NonCallable;
18  }
19  }
20  
21  class Bar {
22  public function bark() {
23  echo 'bark';
24  return $this;
25  }
26  }
27  
28  $foo = new Foo;
29  
30  try {
31  $foo-bar()-bark();
32  } catch(Exception $e) {
33  echo 'something went wrong';
34  return 1;
35  }
36  

Liebe Grüße,
Flavius

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



[PHP-DEV] [RFC] Enum proposal (yet another)

2012-02-21 Thread Samuel Deal
Hi all,

I really missed enums in PHP,
So after reading I tryed to synthetise the various views.

You can find a draft here :
https://github.com/SamNrique/php-src/wiki/RFC-draft
(I can't write on the wiki, and perhaps it's better to finish the
discussion first)

There's an implementation with this draft.
I'd love to have feedbacks because it's my first php-core hack.

Thanks
-- 
Samuel Déal
samuel.d...@gmail.com


Re: [PHP-DEV] [RFC] Enum proposal (yet another)

2012-02-21 Thread Laruence
On Wed, Feb 22, 2012 at 12:45 PM, Samuel Deal samuel.d...@gmail.com wrote:
 Hi all,

 I really missed enums in PHP,
Why? we have class constant.

thanks
 So after reading I tryed to synthetise the various views.

 You can find a draft here :
 https://github.com/SamNrique/php-src/wiki/RFC-draft
 (I can't write on the wiki, and perhaps it's better to finish the
 discussion first)

 There's an implementation with this draft.
 I'd love to have feedbacks because it's my first php-core hack.

 Thanks
 --
 Samuel Déal
 samuel.d...@gmail.com



-- 
Laruence  Xinchen Hui
http://www.laruence.com/

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



Re: [PHP-DEV] PHP Script Compile System

2012-02-21 Thread Flavius Aspra

On 02/22/2012 06:49 AM, Deepak Balani wrote:

Hello all,

I am think(actually drafting) about the compilation system of PHP scripts.
I want to make a native C extension which is able to compile the scripts in
the Zend Engines opcodes and execute directly when called.

The extension may have two functions.

bool gpc_compile($source, $target): compile file to opcodes.
mixed gpc_import($target) Include file to current script.

gpc_import function accepting path to the compiled file and execute file
into the zend engine. I want to know perception of you all about this.

Thank you.
Deepak Balani



Hi

Do you mean something like apc_compile_file()?

I think we already have it.

Or perhaps you mean runkit?

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



Re: [PHP-DEV] [RFC] Enum proposal (yet another)

2012-02-21 Thread Charlie Somerville
Right, but enums could possibly be a lot richer than class constants are
now.

They could be a type where the only values are what's defined in the enum.
This could be used with type hinting:

enum Foo {
A,
B,
C
}

function bar(Foo $x) {
// ...
}

There'd be no need to do any manual checking that $x is a valid value.

Perhaps enum values could also be casted back to strings:

(string)Foo::B; // B

Sure, this is the kind of stuff that's possible in other ways already, but
first class support always helps.
On Feb 22, 2012 4:14 PM, Laruence larue...@php.net wrote:

 On Wed, Feb 22, 2012 at 12:45 PM, Samuel Deal samuel.d...@gmail.com
 wrote:
  Hi all,
 
  I really missed enums in PHP,
 Why? we have class constant.

 thanks
  So after reading I tryed to synthetise the various views.
 
  You can find a draft here :
  https://github.com/SamNrique/php-src/wiki/RFC-draft
  (I can't write on the wiki, and perhaps it's better to finish the
  discussion first)
 
  There's an implementation with this draft.
  I'd love to have feedbacks because it's my first php-core hack.
 
  Thanks
  --
  Samuel Déal
  samuel.d...@gmail.com



 --
 Laruence  Xinchen Hui
 http://www.laruence.com/

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




Re: [PHP-DEV] PHP Script Compile System

2012-02-21 Thread Deepak Balani
No I mean persistent compilation system like

Java

HelloWorld.Java - HelloWorld.class


HelloWorld.php - HelloWorld.gpc

When you call

gpc_import('HelloWorld.php');

then function first look for HelloWorld.gpc if found
then include it and if not then look for HelloWorld.php or HelloWorld.inc
(whatever the setting is) if found compile it and include it else raise an
error.




On Wed, Feb 22, 2012 at 11:25 AM, Flavius Aspra flavius...@gmail.comwrote:

 On 02/22/2012 06:49 AM, Deepak Balani wrote:

 Hello all,

 I am think(actually drafting) about the compilation system of PHP scripts.
 I want to make a native C extension which is able to compile the scripts
 in
 the Zend Engines opcodes and execute directly when called.

 The extension may have two functions.

 bool gpc_compile($source, $target): compile file to opcodes.
 mixed gpc_import($target) Include file to current script.

 gpc_import function accepting path to the compiled file and execute file
 into the zend engine. I want to know perception of you all about this.

 Thank you.
 Deepak Balani


 Hi

 Do you mean something like apc_compile_file()?

 I think we already have it.

 Or perhaps you mean runkit?



RE: [PHP-DEV] PHP Script Compile System

2012-02-21 Thread John Crenshaw
 -Original Message-
 From: Deepak Balani [mailto:wgpdeepak1...@gmail.com] 
 Sent: Wednesday, February 22, 2012 1:07 AM
 To: flav...@php.net
 Cc: internals@lists.php.net
 Subject: Re: [PHP-DEV] PHP Script Compile System

 No I mean persistent compilation system like

 Java

 HelloWorld.Java - HelloWorld.class


 HelloWorld.php - HelloWorld.gpc

 When you call

 gpc_import('HelloWorld.php');

 then function first look for HelloWorld.gpc if found then include it and if 
 not then look for
 HelloWorld.php or HelloWorld.inc (whatever the setting is) if found compile 
 it and include it else
 raise an error.

Can you explain how this is better or functionally different from the behavior 
of APC? APC caches bytecode this way too. Unless I've horribly misunderstood 
something, when you include the file APC uses the cached bytecode as long as it 
is available and the file was not since modified. If the file was modified APC 
recompiles it and caches the bytecode. Sounds like the same net result to me, 
except that APC is less complicated, requires no code changes, and 
automatically clears its own cache.

Did I miss something?

John Crenshaw
Priacta, Inc.

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



Re: [PHP-DEV] PHP Script Compile System

2012-02-21 Thread Rasmus Lerdorf
On 02/21/2012 10:16 PM, John Crenshaw wrote:
 -Original Message-
 From: Deepak Balani [mailto:wgpdeepak1...@gmail.com] 
 Sent: Wednesday, February 22, 2012 1:07 AM
 To: flav...@php.net
 Cc: internals@lists.php.net
 Subject: Re: [PHP-DEV] PHP Script Compile System

 No I mean persistent compilation system like

 Java

 HelloWorld.Java - HelloWorld.class


 HelloWorld.php - HelloWorld.gpc

 When you call

 gpc_import('HelloWorld.php');

 then function first look for HelloWorld.gpc if found then include it and if 
 not then look for
 HelloWorld.php or HelloWorld.inc (whatever the setting is) if found compile 
 it and include it else
 raise an error.
 
 Can you explain how this is better or functionally different from the 
 behavior of APC? APC caches bytecode this way too. Unless I've horribly 
 misunderstood something, when you include the file APC uses the cached 
 bytecode as long as it is available and the file was not since modified. If 
 the file was modified APC recompiles it and caches the bytecode. Sounds like 
 the same net result to me, except that APC is less complicated, requires no 
 code changes, and automatically clears its own cache.
 
 Did I miss something?

There is also apc_bin_dump() and apc_bin_load() if you absolutely must
have something stored on disk, but assuming you are interested in the
performance aspect here, you don't want to be loading anything from disk
on a per-request basis. If the interest is along the lines of being able
to distribute obfuscated binaries or something, then this is completely
the wrong approach because it is trivial to reverse engineer unless you
add an encryption layer on top of it.

I think one thing that people miss when comparing the php compile phase
to java/c/c++ compilation is that compiling a php script to opcodes is
super fast because we don't do complicated optimization passes or any of
those things, so the performance you gain by only skipping the
compilation phase isn't actually that much unless you combine it with
also caching the op_arrays, function and class tables in memory.

Imagine needing to compile a C++ program on every request? That just
isn't feasible. Without an opcode cache, the PHP compiler runs on every
request and it is fast enough for millions of sites out there.

-Rasmus

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



Re: [PHP-DEV] PHP Script Compile System

2012-02-21 Thread Stas Malyshev

Hi!


I am think(actually drafting) about the compilation system of PHP scripts.
I want to make a native C extension which is able to compile the scripts in
the Zend Engines opcodes and execute directly when called.

The extension may have two functions.

bool gpc_compile($source, $target): compile file to opcodes.
mixed gpc_import($target) Include file to current script.


Just FYI: such products already exist. Besides APC that was mentioned, 
there's Zend Guard (commercial), ioncube encoder (commercial), bcompiler 
and maybe more.

Out of curiosity - why you want to do this?

--
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/
(408)454-6900 ext. 227

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