php-general Digest 18 Apr 2008 11:45:31 -0000 Issue 5411
Topics (messages 273213 through 273222):
Re: PHP console script vs C/C++/C#
273213 by: Nathan Nobbe
273219 by: Eric Butera
273222 by: Struan Donald
Re: & performance issues
273214 by: Nathan Nobbe
273218 by: Eric Butera
loop inside a loop
273215 by: Alan Willsher
273216 by: TG
273217 by: Casey
Re: FRench characters not displayed correctly
273220 by: Ford, Mike
273221 by: Robert Cummings
Administrivia:
To subscribe to the digest, e-mail:
[EMAIL PROTECTED]
To unsubscribe from the digest, e-mail:
[EMAIL PROTECTED]
To post to the list, e-mail:
[EMAIL PROTECTED]
----------------------------------------------------------------------
--- Begin Message ---
On Thu, Apr 17, 2008 at 3:30 PM, Daniel Kolbo <[EMAIL PROTECTED]> wrote:
> Hello,
>
> I am writing a PHP script for a local application (not web/html based).
> My script is taking a longer time to execute than I want. The source code
> is a few thousand lines, so I will spare you all this level of detail.
>
> I prefer to write in PHP because that is what I know best. However, I do
> not think there is anything inherent with my script that requires PHP over
> C/C++/C#.
>
> If I wrote the console application in a c language (and compiled) would
> one expect to see any improvements in performance? If so, how much
> improvement could one expect (in general)?
>
> I assume because php is not compiled that this real time interpretation of
> the script by the zend engine must take some time. This is why I am
> thinking about rewriting my whole script in a C language. But before I
> begin that ordeal, i wanted to ask the community for their opinions. If you
> think using a c language would suit me well, what language would you
> recommend?
>
> My google and mail archive searching for this yielded mainly PHP for web
> apps, so I am asking all of you.
>
> My main question is, how much of an improvement in performance will one
> see by using a compiled version of an application versus using a scripted
> version of an application?
>
> I looked at PHP's bcompiler, but the documentation is minimal so I am
> hesitant to dig much deeper into that, unless someone strongly suggests
> otherwise.
here you can c php is much slower than a compiled alternative:
http://shootout.alioth.debian.org/gp4/benchmark.php?test=all&lang=all
-nathan
--- End Message ---
--- Begin Message ---
On Thu, Apr 17, 2008 at 5:30 PM, Daniel Kolbo <[EMAIL PROTECTED]> wrote:
> Hello,
>
> I am writing a PHP script for a local application (not web/html based). My
> script is taking a longer time to execute than I want. The source code is a
> few thousand lines, so I will spare you all this level of detail.
>
> I prefer to write in PHP because that is what I know best. However, I do
> not think there is anything inherent with my script that requires PHP over
> C/C++/C#.
>
> If I wrote the console application in a c language (and compiled) would one
> expect to see any improvements in performance? If so, how much improvement
> could one expect (in general)?
>
> I assume because php is not compiled that this real time interpretation of
> the script by the zend engine must take some time. This is why I am
> thinking about rewriting my whole script in a C language. But before I
> begin that ordeal, i wanted to ask the community for their opinions. If you
> think using a c language would suit me well, what language would you
> recommend?
>
> My google and mail archive searching for this yielded mainly PHP for web
> apps, so I am asking all of you.
>
> My main question is, how much of an improvement in performance will one see
> by using a compiled version of an application versus using a scripted
> version of an application?
>
> I looked at PHP's bcompiler, but the documentation is minimal so I am
> hesitant to dig much deeper into that, unless someone strongly suggests
> otherwise.
>
> Thank you PHPeeps,
> DanK
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
You might take a look at this:
http://us2.php.net/manual/en/function.apc-compile-file.php
I'm not sure if that works on the cli version though. If you wanted
to start making your app faster, just find where your real bottlenecks
are and you can migrate those specific chunks into extensions. Like
for instance if your app does a lot of text processing, you can
migrate that specific set of functions into c since it will be much
faster. If the whole thing is just really slow maybe you should
consider why you've got such a heavy program.
Good luck on your choice!
--- End Message ---
--- Begin Message ---
* at 17/04 16:30 -0500 Daniel Kolbo said:
> Hello,
>
> I am writing a PHP script for a local application (not web/html
> based). My script is taking a longer time to execute than I want. The
> source code is a few thousand lines, so I will spare you all this
> level of detail.
>
> I prefer to write in PHP because that is what I know best. However, I
> do not think there is anything inherent with my script that requires PHP
> over C/C++/C#.
I think this points to an answer. If you're not too familiar with one
of the compiled languages then producing code that runs faster than
your current PHP implementation is a tall order. PHP, like most
scripting languages, is compiled into an internal format as a first
step and it's this that's then run. A lot of effort has gone into
making this pretty fast and by deciding to rewrite in a compiled
language you are betting that the C code, or whatever, you write will
be faster. Given the effort I imagine translating a few thousand
lines of PHP into one of the languages you name is likely to be
significant you'd want to be sure of winning that bet.
> If I wrote the console application in a c language (and compiled) would
> one expect to see any improvements in performance? If so, how much
> improvement could one expect (in general)?
How long will it take you to convert the program? How much more time
will you spend on support and bugfixing?
> I assume because php is not compiled that this real time interpretation
> of the script by the zend engine must take some time. This is why I am
> thinking about rewriting my whole script in a C language. But before I
> begin that ordeal, i wanted to ask the community for their opinions. If
> you think using a c language would suit me well, what language would you
> recommend?
It's not real time interpretation. It's a one time parse and compile
when the script starts and then it runs the internal bytecode. If you
have APC, or some other sort of caching mechanism installed then part
of the speed up comes from caching the bytecode and saving on the
initial parse and compile phase.
As to what language then if you want to go ahead and do this you
should pick the one you know best. If you don't know any of them that
well then I really think that your time would be better spent on
optimising the existing PHP code first. Are you sure it's running as
fast as it can? Do you know where it's slow?
Rewriting it in another language really is the 50 pound lump hammer
solution to the problem if you've not tried anything else to speed it
up.
> My google and mail archive searching for this yielded mainly PHP for web
> apps, so I am asking all of you.
>
> My main question is, how much of an improvement in performance will one
> see by using a compiled version of an application versus using a
> scripted version of an application?
>
> I looked at PHP's bcompiler, but the documentation is minimal so I am
> hesitant to dig much deeper into that, unless someone strongly suggests
> otherwise.
A quick look at the docs tells me that all that bcompiler will do is
save you the initial parse and compile phase and not speed up the
execution of the code.
The one thing you don't say is exactly how long is too long? Is it
hours or minutes? If it's seconds then consider, as someone has
suggested elsewhere in the thread, looking at APC as that should cut
down the start up time of the script.
HTH and apologies if none of this is news to you.
Struan
--- End Message ---
--- Begin Message ---
On Thu, Apr 17, 2008 at 11:51 AM, Eric Butera <[EMAIL PROTECTED]> wrote:
> On Thu, Apr 17, 2008 at 12:00 PM, Nathan Nobbe <[EMAIL PROTECTED]>
> wrote:
> > On Thu, Apr 17, 2008 at 4:57 AM, Bojan Tesanovic <[EMAIL PROTECTED]>
> > wrote:
> >
> >
> > > in PHP5 by default Objects are passed by reference and as you can see
> at
> > > this graph passing array by reference in PHP5 is slower
> > > http://nathan.moxune.com/arrayVsArrayIteratorReport.php
> >
> >
> > wow, thats hilarious, thats my own chart :O ROTFL
> >
> > im glad somebody else thought something of it ;)
> >
> > -nathan
> >
>
> I almost spit my water out when I saw that link directed at you.
good times!
> Your
> work is famous! ;)
well i do what i can :D
I don't have an actual answer as far as benchmarks go. I've been
> converting all of my sites from php4 to 5 over the past 3 months
> stripping out &'s as I go. I haven't noticed any differences myself
> though. But then again I've been adding in type hints and visibility
> too so I'm sure that isn't helping.
yea; i hadnt thought of the overhead of adding visibility / type hinting
in. but if im adding those, either way; the extra cost from the & can be
gained back if theyre yanked.
I'm always pimping Xdebug, so just remember it will show you where
> your real bottlenecks are instead of guessing. *shrug*
xdebug is da bomb; thats what i used to build the charts from the
performance report ;)
ok, so heres what im thinking. any functions that return by reference can
safely be changed, right? so i could do a mass replace like this
find: 'function &'
replace: 'function '
note, there is a space after function in the replace. i think the only
reason to use return by reference is when returning an object to avoid
getting a copy back in the php4 days. the rest im thinking can be done by
hand as time goes on. waddya all think?
thx,
-nathan
--- End Message ---
--- Begin Message ---
On Thu, Apr 17, 2008 at 7:10 PM, Nathan Nobbe <[EMAIL PROTECTED]> wrote:
> On Thu, Apr 17, 2008 at 11:51 AM, Eric Butera <[EMAIL PROTECTED]> wrote:
>
> >
> >
> >
> > On Thu, Apr 17, 2008 at 12:00 PM, Nathan Nobbe <[EMAIL PROTECTED]>
> wrote:
> > > On Thu, Apr 17, 2008 at 4:57 AM, Bojan Tesanovic <[EMAIL PROTECTED]>
> > > wrote:
> > >
> > >
> > > > in PHP5 by default Objects are passed by reference and as you can see
> at
> > > > this graph passing array by reference in PHP5 is slower
> > > > http://nathan.moxune.com/arrayVsArrayIteratorReport.php
> > >
> > >
> > > wow, thats hilarious, thats my own chart :O ROTFL
> > >
> > > im glad somebody else thought something of it ;)
> > >
> > > -nathan
> > >
> >
> > I almost spit my water out when I saw that link directed at you.
>
> good times!
>
> > Your
> > work is famous! ;)
>
> well i do what i can :D
>
>
> > I don't have an actual answer as far as benchmarks go. I've been
> > converting all of my sites from php4 to 5 over the past 3 months
> > stripping out &'s as I go. I haven't noticed any differences myself
> > though. But then again I've been adding in type hints and visibility
> > too so I'm sure that isn't helping.
>
> yea; i hadnt thought of the overhead of adding visibility / type hinting in.
> but if im adding those, either way; the extra cost from the & can be gained
> back if theyre yanked.
>
>
> > I'm always pimping Xdebug, so just remember it will show you where
> > your real bottlenecks are instead of guessing. *shrug*
>
> xdebug is da bomb; thats what i used to build the charts from the
> performance report ;)
>
> ok, so heres what im thinking. any functions that return by reference can
> safely be changed, right? so i could do a mass replace like this
>
> find: 'function &'
> replace: 'function '
>
> note, there is a space after function in the replace. i think the only
> reason to use return by reference is when returning an object to avoid
> getting a copy back in the php4 days. the rest im thinking can be done by
> hand as time goes on. waddya all think?
>
> thx,
>
> -nathan
>
Should be ok, but that is what unit tests are for, right? ;) I only
used return by reference when returning objects. I think referencing
array inputs would be more of a challenge if there was any trickery
going on there. The return value should just be a final here you go
since the function is done at that point. Guess you'll find out when
you try it. Just make a backup first! :)
--- End Message ---
--- Begin Message ---
Hi can you put a loop inside a loop?
what I want to do is have something looping every 1 second and then
something else looping once every 10 seconds.
something like a combination of these two..
$x = 0;
while ($x < 1000) {
echo "1";
$x++;
sleep(1);
}
$y = 0;
while ($y < 100) {
echo "2";
$y++;
sleep(10);
}
but at the same time so it would output something like
1111111111211111111112111111111121111111112
Thanks
--- End Message ---
--- Begin Message ---
Yup.. you can do that. Easiest way to find out is to give it a try :)
As long as your loop conditions don't conflict or you do stuff to change
variables in a counter-productive way (ie. breaking your logic) then you
should be ok.
-TG
----- Original Message -----
From: "Alan Willsher" <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED]
Date: Fri, 18 Apr 2008 02:51:02 +0100
Subject: [PHP] loop inside a loop
> Hi can you put a loop inside a loop?
>
> what I want to do is have something looping every 1 second and then
> something else looping once every 10 seconds.
>
> something like a combination of these two..
>
> $x = 0;
> while ($x < 1000) {
> echo "1";
> $x++;
> sleep(1);
> }
>
> $y = 0;
> while ($y < 100) {
> echo "2";
> $y++;
> sleep(10);
> }
>
> but at the same time so it would output something like
>
> 1111111111211111111112111111111121111111112
>
> Thanks
>
>
--- End Message ---
--- Begin Message ---
On Thu, Apr 17, 2008 at 6:51 PM, Alan Willsher
<[EMAIL PROTECTED]> wrote:
> Hi can you put a loop inside a loop?
>
> what I want to do is have something looping every 1 second and then
> something else looping once every 10 seconds.
>
> something like a combination of these two..
>
> $x = 0;
> while ($x < 1000) {
> echo "1";
> $x++;
> sleep(1);
> }
>
> $y = 0;
> while ($y < 100) {
> echo "2";
> $y++;
> sleep(10);
> }
>
> but at the same time so it would output something like
>
> 1111111111211111111112111111111121111111112
>
> Thanks
>
<?php
$x = 0;
while ($x < 1000) {
echo "1";
$x++;
if ($x % 10 == 9)
echo "2";
sleep(1);
}
?>
:)
--
-Casey
--- End Message ---
--- Begin Message ---
On 17 April 2008 10:05, Robert Cummings advised:
> On Thu, 2008-04-17 at 10:57 +0200, Angelo Zanetti wrote:
>>
>> Thanks Robert,
>>
>> I have the following headers:
>>
>>
>> http://fr.xxxx.com/student/themes/english/locker_room/student.html
>>
>> GET /student/themes/english/locker_room/student.html? HTTP/1.1 Host:
>> fr.xxxx.com User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1;
en-US;
>> rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14
>> Accept:
>>
> text/xml,application/xml,application/xhtml+xml,text/html;q=0.9
> ,text/plain;q=
>> 0.8,image/png,*/*;q=0.5
>> Accept-Language: en-us,en;q=0.5
>> Accept-Encoding: gzip,deflate
>> Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
>> Keep-Alive: 300
>> Connection: keep-alive
>> Referer:
> http://fr.xxxx.com/student/themes/english/locker_room/student.html
>> Cookie: PHPSESSID=818678404c170c8e4f5d237c1d0280a8
>> If-Modified-Since: Sat, 17 Nov 2007 11:40:26 GMT
>> If-None-Match: "6b97e-a9d-619b9e80"
>> Cache-Control: max-age=0
>>
>> HTTP/1.x 304 Not Modified
>> Date: Thu, 17 Apr 2008 08:31:32 GMT
>> Server: Apache/2.0.55 (Unix) PHP/5.1.2
>> Connection: Keep-Alive
>> Keep-Alive: timeout=15, max=200
>> Etag: "6b97e-a9d-619b9e80"
>> -----------------------------
>>
>>
>> Now I see that the headers have:
>>
>> Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
>>
>> Which to me seems like it is sending both ISO-8859-1 and UTF-8?
>
> No, that's what kind of content the server is willing to accept from
> various sources such as POST.
Er, no, that's what kind of content the browser is prepared to accept
back from the server -- the headers starting from the GET line are what
the browser sends to the server as part of the request. The lines
starting at the HTTP/1.x line are what the server returns.
In this case, you're getting a 304 Not Modified, which means the server
is not even serving any content on this request, nor, probably, even a
full set of headers -- it's just telling the browser it can use its
cached page. To be absolutely sure what the relevant headers are, you
need to force the server to send the full page -- usually, the best way
to do this is to hold down the Ctrl key whilst clicking the
Refresh/Reload button.
Incidentally, I notice that what's being served here is a .html page,
and the presence of a 304 response, and no PHP headers, suggests it
actually is plain HTML, and not a disguised script, so this whole thread
is really very OT...!! ;) However, this being the case, it suggests you
have a static .html file on your site claiming to be charset=utf-8, but
not saved in UTF-8! There are two obvious ways to solve this: (i)
convert the file into UTF-8, or (ii) edit it to have the correct
charset= value in the tag.
Cheers!
--
Mike Ford, Electronic Information Services Adviser,
JG125, The Headingley Library,
James Graham Building, Leeds Metropolitan University,
Headingley Campus, LEEDS, LS6 3QS, United Kingdom
Email: [EMAIL PROTECTED]
Tel: +44 113 812 4730 Fax: +44 113 812 3211
To view the terms under which this email is distributed, please go to
http://disclaimer.leedsmet.ac.uk/email.htm
--- End Message ---
--- Begin Message ---
On Thu, 2008-04-17 at 11:24 +0100, Ford, Mike wrote:
> On 17 April 2008 10:05, Robert Cummings advised:
>
> > On Thu, 2008-04-17 at 10:57 +0200, Angelo Zanetti wrote:
> >>
> >> Thanks Robert,
> >>
> >> I have the following headers:
> >>
> >>
> >> http://fr.xxxx.com/student/themes/english/locker_room/student.html
> >>
> >> GET /student/themes/english/locker_room/student.html? HTTP/1.1 Host:
> >> fr.xxxx.com User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1;
> en-US;
> >> rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14
> >> Accept:
> >>
> > text/xml,application/xml,application/xhtml+xml,text/html;q=0.9
> > ,text/plain;q=
> >> 0.8,image/png,*/*;q=0.5
> >> Accept-Language: en-us,en;q=0.5
> >> Accept-Encoding: gzip,deflate
> >> Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
> >> Keep-Alive: 300
> >> Connection: keep-alive
> >> Referer:
> > http://fr.xxxx.com/student/themes/english/locker_room/student.html
> >> Cookie: PHPSESSID=818678404c170c8e4f5d237c1d0280a8
> >> If-Modified-Since: Sat, 17 Nov 2007 11:40:26 GMT
> >> If-None-Match: "6b97e-a9d-619b9e80"
> >> Cache-Control: max-age=0
> >>
> >> HTTP/1.x 304 Not Modified
> >> Date: Thu, 17 Apr 2008 08:31:32 GMT
> >> Server: Apache/2.0.55 (Unix) PHP/5.1.2
> >> Connection: Keep-Alive
> >> Keep-Alive: timeout=15, max=200
> >> Etag: "6b97e-a9d-619b9e80"
> >> -----------------------------
> >>
> >>
> >> Now I see that the headers have:
> >>
> >> Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
> >>
> >> Which to me seems like it is sending both ISO-8859-1 and UTF-8?
> >
> > No, that's what kind of content the server is willing to accept from
> > various sources such as POST.
>
> Er, no, that's what kind of content the browser is prepared to accept
> back from the server -- the headers starting from the GET line are what
> the browser sends to the server as part of the request. The lines
> starting at the HTTP/1.x line are what the server returns.
Good catch, I must have crossed wires somewhere in my head and thought
about the accept-charset attribute for forms which *is* what the server
is willing to accept when processing the form.
Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP
--- End Message ---