Re: [PHP] To ?> or not to ?>

2012-04-03 Thread Robert Cummings

On 12-04-04 01:14 AM, Donovan Brooke wrote:

Robert Cummings wrote:
[snip]

Could using ob_start and ob_end_flush eliminate the ambiguity of whether
or not to use '?>'?


In the generally recommended case of don't use them at the end of your
file... where's the ambiguity?



http://www.php.net/manual/en/function.include.php

http://www.php.net/manual/en/language.basic-syntax.phpmode.php

Those seem to suggest to use them... thus the ambiguity.


From an age long gone when I asked the exact same question and Big 
Daddy answered:


http://marc.info/?l=php-internals&m=106896382030183&w=2

Then again a couple of years later:

http://marc.info/?l=php-internals&m=112537775409619&w=2

And in the manual itself (see the note):

http://ca.php.net/basic-syntax.instruction-separation

Zend Framework and Drupal are examples of large codebases that have 
adopted the omission as a best practice.


Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] RSS Standardness

2012-04-03 Thread shiplu
Dealing RSS Version.

I am going to write an RSS parser. Its a very simple parser which just
grabs the latest items date and title. SimpleXML and DomDocument is my
friend here. The problem here is there are too many standards for RSS. RSS
2.0, 0.92 and 0.91. What do you think which version should I implement? if
its not a single version then which versions?  I am also aware about
SimplePie which I have been using a lot. Here my preference is not to load
a library like SimplePie to just grab the title and date. I just want to
use DomDocument and SimpleXML.


Content-Type header.

RSS were called RDF prior to 0.91 and currently RDF is a different
protocol. How do you detect if the content is RSS 0.90 or Modern RDF if
content-type header is 'Application/rdf+xml'. Other content type with same
meaning is 'Application/rdf' and 'text/rdf'.

-- 
Shiplu.Mokadd.im
ImgSign.com | A dynamic signature machine
Innovation distinguishes between follower and leader


Re: [PHP] To ?> or not to ?>

2012-04-03 Thread shiplu
I keep my closing tag. Earlier I started removing closing tag. Then I
search for the standardness of this practice and found its not standard.
Some frameworks/cms intentionally do this. Besides a signle `\n` character
is allowed after the closing tag which does not cause "Can not send Header"
error.  So I started using closing tag again.  Later I found, from visual
aspect, a closing tag makes the code balanced.
Still using it.
-- 
Shiplu.Mokadd.im
ImgSign.com | A dynamic signature machine
Innovation distinguishes between follower and leader


Re: [PHP] To ?> or not to ?>

2012-04-03 Thread Donovan Brooke

Robert Cummings wrote:
[snip]

Could using ob_start and ob_end_flush eliminate the ambiguity of whether
or not to use '?>'?


In the generally recommended case of don't use them at the end of your
file... where's the ambiguity?



http://www.php.net/manual/en/function.include.php

http://www.php.net/manual/en/language.basic-syntax.phpmode.php

Those seem to suggest to use them... thus the ambiguity.


Donovan





--
D Brooke

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] To ?> or not to ?>

2012-04-03 Thread Robert Cummings

On 12-04-03 11:39 PM, Donovan Brooke wrote:

Stuart Dallas wrote:
[snip]

Usually when setting headers after such a script has been included when output 
buffering is turned off. Personally I never put the closing ?>   in if it's at 
the end of the file because it's unnecessary and can cause issues if it's present, 
but it's personal preference more than anything else.

Ultimately you have to consider that there's a reason it's optional - things like that 
don't generally happen by accident. I remember Rasmus commenting on this style issue a 
few years back so a search of the archives should find an "official" position.

-Stuart



Could using ob_start and ob_end_flush eliminate the ambiguity of whether
or not to use '?>'?


In the generally recommended case of don't use them at the end of your 
file... where's the ambiguity?


Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] To ?> or not to ?>

2012-04-03 Thread Donovan Brooke

Stuart Dallas wrote:
[snip]

Usually when setting headers after such a script has been included when output 
buffering is turned off. Personally I never put the closing ?>  in if it's at 
the end of the file because it's unnecessary and can cause issues if it's present, 
but it's personal preference more than anything else.

Ultimately you have to consider that there's a reason it's optional - things like that 
don't generally happen by accident. I remember Rasmus commenting on this style issue a 
few years back so a search of the archives should find an "official" position.

-Stuart



Could using ob_start and ob_end_flush eliminate the ambiguity of whether 
or not to use '?>'?


Donovan




--
D Brooke

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] learning resources for PHP

2012-04-03 Thread Tim Dunphy
Hello list,

 I am quite sure that you've heard this question at least a few times
before. :) But I have been dabbling a bit in PHP for years and I've
decided that its' high time that became serious about getting a solid
grounding in it. Currently I work as a Sysadmin and have modest but
reliable skills in bash and perl. But I consider PHP more of an
artform and I really need to 'pick up a brush and start painting' so
to speak.

 So what I was wondering what websites, and books you'd recommend to
someone who (for all intents and purpose) is just starting out.

 On my hit list of things to learn are basic php / database
interaction (mysql mainly).. then how to accelerate php interraction
through memcache.. and eventually one I have all that down onto using
some of the NoSQLs (mongo/cassandra/membase, etc).

Thanks!

-- 
GPG me!!

gpg --keyserver pool.sks-keyservers.net --recv-keys F186197B

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: To ?> or not to ?>

2012-04-03 Thread Ross McKay
On Tue, 3 Apr 2012 17:29:33 -0400, Tedd Sperling wrote:

>[...]
>Does anyone have more examples of where scripts will fail 
>IF they end with "?> " (note the additional space)?

+1 on everyone's call to omit on an included file due to the potential
for sending headers.

>[... rearranged for ease of reply ...]
>You see, the scripts created image but apparently the image 
>delivery method objected to the additional whitespace.

If you're sending binary data, you're best throwing in an exit() after
the last output. It doesn't matter then whether or not you have a
closing ?>, with or without additional white space.
-- 
Ross McKay, Toronto, NSW Australia
"The chief cause of problems is solutions" -Eric Sevareid

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] To ?> or not to ?>

2012-04-03 Thread Joshua Kehn
I leave them off of any non-view PHP file. It doesn't have any downsides, and 
leaving them in can cause problems. Just like short tags! 

Regards,

–Josh

Joshua Kehn | @joshkehn 
http://joshuakehn.com

On Apr 3, 2012, at 5:29 PM, Tedd Sperling wrote:

> Hi gang:
> 
> Let me start a religious war -- should one end their scripts with "?>" or not?
> 
> After years of never having a problem with ending any of my scripts with 
> "?>", I found that several students in my class had scripts that did not 
> produce the desired result even after they were given the scripts via 
> highlight_file(") to cut and paste.
> 
> As it turned out, several students copy/pasted the script with an addition 
> whitespace after the ending "?>" and as such the scripts did not run as 
> expected. You see, the scripts created image but apparently the image 
> delivery method objected to the additional whitespace.
> 
> Does anyone have more examples of where scripts will fail IF they end with 
> "?> " (note the additional space)?
> 
> Cheers,
> 
> tedd
> 
> _
> tedd.sperl...@gmail.com
> http://sperling.com
> 
> 
> 
> 
> 
> 
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 



Re: [PHP] To ?> or not to ?>

2012-04-03 Thread Robert Cummings


On 12-04-03 05:29 PM, Tedd Sperling wrote:

Hi gang:

Let me start a religious war -- should one end their scripts with "?>" or not?

After years of never having a problem with ending any of my scripts with "?>", I 
found that several students in my class had scripts that did not produce the desired result even 
after they were given the scripts via highlight_file(") to cut and paste.

As it turned out, several students copy/pasted the script with an addition whitespace after 
the ending "?>" and as such the scripts did not run as expected. You see, the 
scripts created image but apparently the image delivery method objected to the additional 
whitespace.

Does anyone have more examples of where scripts will fail IF they end with "?>  
" (note the additional space)?


It's standard practice to NOT include the closing ?> on anything 
remotely resembling a class or lib source file. As has been mentioned on 
this list and originally on PHP internals on several occasions, the 
optionality of the closing tag is intentional :)


Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] To ?> or not to ?>

2012-04-03 Thread Mari Masuda

On Apr 3, 2012, at 2:29 PM, Tedd Sperling wrote:

> Hi gang:
> 
> Let me start a religious war -- should one end their scripts with "?>" or not?
> 
> After years of never having a problem with ending any of my scripts with 
> "?>", I found that several students in my class had scripts that did not 
> produce the desired result even after they were given the scripts via 
> highlight_file(") to cut and paste.
> 
> As it turned out, several students copy/pasted the script with an addition 
> whitespace after the ending "?>" and as such the scripts did not run as 
> expected. You see, the scripts created image but apparently the image 
> delivery method objected to the additional whitespace.
> 
> Does anyone have more examples of where scripts will fail IF they end with 
> "?> " (note the additional space)?
> 
> Cheers,
> 
> tedd

I believe this can also be problematic if script A ends with "?> " (with 
additional space) and script B includes script A at the top, which will cause 
the headers to be sent.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] To ?> or not to ?>

2012-04-03 Thread Stuart Dallas
On 3 Apr 2012, at 22:29, Tedd Sperling wrote:

> Let me start a religious war -- should one end their scripts with "?>" or not?
> 
> After years of never having a problem with ending any of my scripts with 
> "?>", I found that several students in my class had scripts that did not 
> produce the desired result even after they were given the scripts via 
> highlight_file(") to cut and paste.
> 
> As it turned out, several students copy/pasted the script with an addition 
> whitespace after the ending "?>" and as such the scripts did not run as 
> expected. You see, the scripts created image but apparently the image 
> delivery method objected to the additional whitespace.
> 
> Does anyone have more examples of where scripts will fail IF they end with 
> "?> " (note the additional space)?

Usually when setting headers after such a script has been included when output 
buffering is turned off. Personally I never put the closing ?> in if it's at 
the end of the file because it's unnecessary and can cause issues if it's 
present, but it's personal preference more than anything else.

Ultimately you have to consider that there's a reason it's optional - things 
like that don't generally happen by accident. I remember Rasmus commenting on 
this style issue a few years back so a search of the archives should find an 
"official" position.

-Stuart

-- 
Stuart Dallas
3ft9 Ltd
http://3ft9.com/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] To ?> or not to ?>

2012-04-03 Thread Tedd Sperling
Hi gang:

Let me start a religious war -- should one end their scripts with "?>" or not?

After years of never having a problem with ending any of my scripts with "?>", 
I found that several students in my class had scripts that did not produce the 
desired result even after they were given the scripts via highlight_file(") to 
cut and paste.

As it turned out, several students copy/pasted the script with an addition 
whitespace after the ending "?>" and as such the scripts did not run as 
expected. You see, the scripts created image but apparently the image delivery 
method objected to the additional whitespace.

Does anyone have more examples of where scripts will fail IF they end with "?> 
" (note the additional space)?

Cheers,

tedd

_
tedd.sperl...@gmail.com
http://sperling.com






--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Node.PHP

2012-04-03 Thread Joseph Moniz
*bad link in last post

http://luvit.io/


-Joseph Moniz



On Tue, Apr 3, 2012 at 12:16 PM, Joseph Moniz  wrote:
> On Fri, Mar 30, 2012 at 5:56 PM, German Geek  wrote:
>> Maybe stupid question, but is node.php really necessary? If you can program
>> PHP and it performs better than node.js, why would you need to have another
>> wrapper around things. Why not just program "normal" PHP?
>
> This is normal PHP in the same sense that node.js is normal
> javascript, python-tornado is normal python and ruby-event-machine is
> normal ruby. The only difference as stated by micheal was the async
> IO.
>
> On Fri, Mar 30, 2012 at 6:33 PM, Michael Save
>  wrote:
>> Also, I kind of doubt you can outperform node.js with standard PHP.
>
> On Sat, Mar 31, 2012 at 9:37 AM, Daniel Brown  wrote:
>> On Fri, Mar 30, 2012 at 21:33, Michael Save
>>  wrote:
>>> Because "normal" PHP is not asynchronous.
>>>
>>> Also, I kind of doubt you can outperform node.js with standard PHP.
>>
>>    Your doubts are indeed well-grounded.  Using node.js (indeed,
>> V8-based apps in general) are compiled as native machine code, which
>> don't require the added overhead of a parser, such as PHP.
>
> This has been an on the side just for fun project for me mostly and as
> such i originally had the same performance assumptions as stated in
> this thread. Basically i was writing this "to get familar with php
> internals and to understand what goes into designing such a system".
>
> You can imagine my surprise when i ran bench marks against the example
> server against an equivelant node.js http server and the node.php
> implementation was able to respond to twice as many requests per
> second (14k req/s) then node.js could (7k req/s). Though i would take
> this with a grain of salt as the benchmark is largely unfair seeing
> how node.js is much more feature complete and hardend from production
> use. Never the less, i was absolutely shocked that this completely
> unoptomized and memory leaky node.php implementation i hacked together
> in one night was able to run circles around node.js in naive
> benchmarks.
>
> So i was absolutely confused to the performance boost with php so i
> started poking around asking people in various freenode channels if
> they had any hypothesis on why node.php was able to perform against
> node.js.
>
> I stumbled across a similar project to create a node.lua
> implemantation called luvit ( http://www.luvit.io ) and it also
> boasted the same exact performance boost vs node.js, thats is luvit
> was able to do 2x the requests as node.js in the same amount of time.
>
> From my exploration on nodes 1/2x performance vs node.php and luvit
> (node.lua) it turns out that V8 is fast only when it has to stay in JS
> mode. The problem with node like systems is the JS to native code
> boundary must be crossed several times to perform IO. So nodejs-core
> get's some of it's best performance boosts from reducing the amount of
> times JS has to call out to C++. The unfortunate detail is that
> node.js like systems get their "power" from doing lots of IO and every
> IO operation has to call out to C/C++ so node.js performance really
> drags around this gotcha in V8.
>
> I hold out some hope for native PHP performance tough. If some one
> were to invest the time into making a solid JIT based interpreter for
> PHP i'm fairly confident based on language characteristics and the
> performance characteristics associated with them that a PHP-JIT
> implementation would be able to leave V8 in the dust. Mostly due to
> explicit lexical scoping in PHP that would offset the Hidden-Class
> overhead of V8.
>
> In terms of PHP-JITs Facebook has already done some initial work on
> such a VM, they call it, not surprisingly, hip-hop-virtual-machine (
> http://www.facebook.com/note.php?note_id=10150415177928920 ) and it
> already doing almost no optimizations is closer to performance of
> compiled PHP via hiphop then it is to interpreted PHP via the de facto
> interpreter.
>
> - Joseph Moniz
>
>
>
>   With that
>> said, compiling PHP (such as with HopHop) would give at least
>> comparable performance results.
>>
>>    Still, all in all, I would never discourage someone doing a
>> 'node.php' application.  While its performance may not be quite as
>> good speed-wise, that doesn't mean it can't become more robust, more
>> generally-applicable, or even just find niche uses.  I've written
>> numerous socket servers in PHP for a variety of clients and uses,
>> where they made sense (speed of deployment, ease of code-management by
>> a number of developers who don't know C, et cetera).  I can easily see
>> where this could add value.
>>
>> --
>> 
>> Network Infrastructure Manager
>> http://www.php.net/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Node.PHP

2012-04-03 Thread Joseph Moniz
On Fri, Mar 30, 2012 at 5:56 PM, German Geek  wrote:
> Maybe stupid question, but is node.php really necessary? If you can program
> PHP and it performs better than node.js, why would you need to have another
> wrapper around things. Why not just program "normal" PHP?

This is normal PHP in the same sense that node.js is normal
javascript, python-tornado is normal python and ruby-event-machine is
normal ruby. The only difference as stated by micheal was the async
IO.

On Fri, Mar 30, 2012 at 6:33 PM, Michael Save
 wrote:
> Also, I kind of doubt you can outperform node.js with standard PHP.

On Sat, Mar 31, 2012 at 9:37 AM, Daniel Brown  wrote:
> On Fri, Mar 30, 2012 at 21:33, Michael Save
>  wrote:
>> Because "normal" PHP is not asynchronous.
>>
>> Also, I kind of doubt you can outperform node.js with standard PHP.
>
>    Your doubts are indeed well-grounded.  Using node.js (indeed,
> V8-based apps in general) are compiled as native machine code, which
> don't require the added overhead of a parser, such as PHP.

This has been an on the side just for fun project for me mostly and as
such i originally had the same performance assumptions as stated in
this thread. Basically i was writing this "to get familar with php
internals and to understand what goes into designing such a system".

You can imagine my surprise when i ran bench marks against the example
server against an equivelant node.js http server and the node.php
implementation was able to respond to twice as many requests per
second (14k req/s) then node.js could (7k req/s). Though i would take
this with a grain of salt as the benchmark is largely unfair seeing
how node.js is much more feature complete and hardend from production
use. Never the less, i was absolutely shocked that this completely
unoptomized and memory leaky node.php implementation i hacked together
in one night was able to run circles around node.js in naive
benchmarks.

So i was absolutely confused to the performance boost with php so i
started poking around asking people in various freenode channels if
they had any hypothesis on why node.php was able to perform against
node.js.

I stumbled across a similar project to create a node.lua
implemantation called luvit ( http://www.luvit.io ) and it also
boasted the same exact performance boost vs node.js, thats is luvit
was able to do 2x the requests as node.js in the same amount of time.

>From my exploration on nodes 1/2x performance vs node.php and luvit
(node.lua) it turns out that V8 is fast only when it has to stay in JS
mode. The problem with node like systems is the JS to native code
boundary must be crossed several times to perform IO. So nodejs-core
get's some of it's best performance boosts from reducing the amount of
times JS has to call out to C++. The unfortunate detail is that
node.js like systems get their "power" from doing lots of IO and every
IO operation has to call out to C/C++ so node.js performance really
drags around this gotcha in V8.

I hold out some hope for native PHP performance tough. If some one
were to invest the time into making a solid JIT based interpreter for
PHP i'm fairly confident based on language characteristics and the
performance characteristics associated with them that a PHP-JIT
implementation would be able to leave V8 in the dust. Mostly due to
explicit lexical scoping in PHP that would offset the Hidden-Class
overhead of V8.

In terms of PHP-JITs Facebook has already done some initial work on
such a VM, they call it, not surprisingly, hip-hop-virtual-machine (
http://www.facebook.com/note.php?note_id=10150415177928920 ) and it
already doing almost no optimizations is closer to performance of
compiled PHP via hiphop then it is to interpreted PHP via the de facto
interpreter.

- Joseph Moniz



  With that
> said, compiling PHP (such as with HopHop) would give at least
> comparable performance results.
>
>    Still, all in all, I would never discourage someone doing a
> 'node.php' application.  While its performance may not be quite as
> good speed-wise, that doesn't mean it can't become more robust, more
> generally-applicable, or even just find niche uses.  I've written
> numerous socket servers in PHP for a variety of clients and uses,
> where they made sense (speed of deployment, ease of code-management by
> a number of developers who don't know C, et cetera).  I can easily see
> where this could add value.
>
> --
> 
> Network Infrastructure Manager
> http://www.php.net/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: learning resources for PHP

2012-04-03 Thread Daniel Brown
On Mon, Apr 2, 2012 at 23:53, Tim Dunphy  wrote:
> Hello list,
>
>  I am quite sure that you've heard this question at least a few times
> before. :) But I have been dabbling a bit in PHP for years and I've
> decided that its' high time that became serious about getting a solid
> grounding in it. Currently I work as a Sysadmin and have modest but
> reliable skills in bash and perl. But I consider PHP more of an
> artform and I really need to 'pick up a brush and start painting' so
> to speak.
>
>  So what I was wondering what websites, and books you'd recommend to
> someone who (for all intents and purpose) is just starting out.
>
>  On my hit list of things to learn are basic php / database
> interaction (mysql mainly).. then how to accelerate php interraction
> through memcache.. and eventually one I have all that down onto using
> some of the NoSQLs (mongo/cassandra/membase, etc).
>
> Thanks!
>
> -tim
>
>
> --
> GPG me!!
>
> gpg --keyserver pool.sks-keyservers.net --recv-keys F186197B

Your question is better asked (and will certainly be better
answered) on the general list at php-general@lists.php.net, Tim, and
I've CC'd the list for you.  If you haven't already, please subscribe
to that list to ensure you receive all the responses.

-- 

Network Infrastructure Manager
http://www.php.net/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php