FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Including PHP scripts on same server
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
Including PHP scripts on same server [message #171745] Thu, 20 January 2011 06:18 Go to next message
jwcarlton is currently offline  jwcarlton
Messages: 76
Registered: December 2010
Karma: 0
Member
I currently have several functions scripted on one page. If I move
these to several different PHP files and then include them on the
original page, will this be any slower (or cause more of a server
load) than having them coded directly on the page?

For me, this would only be a convenience; I have a particularly
complex file with large sections, and it would be easier for me to be
able to update sections without working on the entire file at once.
But if it would be slower or cause a higher server load, then it's not
really necessary.
Re: Including PHP scripts on same server [message #171746 is a reply to message #171745] Thu, 20 January 2011 07:07 Go to previous messageGo to next message
Michael Fesser is currently offline  Michael Fesser
Messages: 215
Registered: September 2010
Karma: 0
Senior Member
.oO(jwcarlton)

> I currently have several functions scripted on one page. If I move
> these to several different PHP files and then include them on the
> original page, will this be any slower (or cause more of a server
> load) than having them coded directly on the page?

Most likely you won't notice any difference. If you should really
encounter performance problems, use a profiler to check your code.

> For me, this would only be a convenience; I have a particularly
> complex file with large sections, and it would be easier for me to be
> able to update sections without working on the entire file at once.

Then just do it.

Micha
Re: Including PHP scripts on same server [message #171891 is a reply to message #171745] Thu, 20 January 2011 12:02 Go to previous messageGo to next message
Captain Paralytic is currently offline  Captain Paralytic
Messages: 204
Registered: September 2010
Karma: 0
Senior Member
On Jan 20, 6:18 am, jwcarlton <jwcarl...@gmail.com> wrote:
> I currently have several functions scripted on one page.
No you don't. A "page" (or more correctly a document) is what someone
sees on a browser. It is not the same as a php file.

One php file may generate many html pages or many php files may
generate only 1 page.

Do not confuse the 2.
Re: Including PHP scripts on same server [message #171900 is a reply to message #171891] Thu, 20 January 2011 17:25 Go to previous messageGo to next message
jwcarlton is currently offline  jwcarlton
Messages: 76
Registered: December 2010
Karma: 0
Member
On Jan 20, 7:02 am, Captain Paralytic <paul_laut...@yahoo.com> wrote:
> On Jan 20, 6:18 am, jwcarlton <jwcarl...@gmail.com> wrote:> I currently have several functions scripted on one page.
>
> No you don't. A "page" (or more correctly a document) is what someone
> sees on a browser. It is not the same as a php file.
>
> One php file may generate many html pages or many php files may
> generate only 1 page.
>
> Do not confuse the 2.

I'm really not sure how I would have said this correctly. What I'm
referring to aren't really functions, either; they're sections of a
single page that is created (executed?) via PHP.

For example, consider the Yahoo.com homepage. What if each section
(the navigation, the main news in the middle, "Trending Now" to the
right, the Google ad, "Marketplace" below, and "Popular Travel" beside
of it) were each including a separate PHP file to create them? Would
this be slower, or the same, as compared to them being coded in a
single file?
Re: Including PHP scripts on same server [message #171906 is a reply to message #171900] Thu, 20 January 2011 19:38 Go to previous messageGo to next message
Captain Paralytic is currently offline  Captain Paralytic
Messages: 204
Registered: September 2010
Karma: 0
Senior Member
On Jan 20, 5:25 pm, jwcarlton <jwcarl...@gmail.com> wrote:
> On Jan 20, 7:02 am, Captain Paralytic <paul_laut...@yahoo.com> wrote:
>
>> On Jan 20, 6:18 am, jwcarlton <jwcarl...@gmail.com> wrote:> I currently have several functions scripted on one page.
>
>> No you don't. A "page" (or more correctly a document) is what someone
>> sees on a browser. It is not the same as a php file.
>
>> One php file may generate many html pages or many php files may
>> generate only 1 page.
>
>> Do not confuse the 2.
>
> I'm really not sure how I would have said this correctly. What I'm
> referring to aren't really functions, either; they're sections of a
> single page that is created (executed?) via PHP.
>
> For example, consider the Yahoo.com homepage. What if each section
> (the navigation, the main news in the middle, "Trending Now" to the
> right, the Google ad, "Marketplace" below, and "Popular Travel" beside
> of it) were each including a separate PHP file to create them? Would
> this be slower, or the same, as compared to them being coded in a
> single file?

Why does it matter. If you're that concerned about speed of execution,
why are you using php in the first place? You should code your site in
C.

And even if you had a single php file, think of all those newline
characters that have to be read in. Better put everytihing on a single
line.

Oh and don't have variable names that are longer than necessary, it
all increases the time the file takes to be read, so just use single
letters for all variable names.
Re: Including PHP scripts on same server [message #171911 is a reply to message #171906] Thu, 20 January 2011 21:46 Go to previous messageGo to next message
jwcarlton is currently offline  jwcarlton
Messages: 76
Registered: December 2010
Karma: 0
Member
> Why does it matter. If you're that concerned about speed of execution,
> why are you using php in the first place? You should code your site in
> C.

That's actually a very good question. If I were a better C programmer,
I probably would :-)


> And even if you had a single php file, think of all those newline
> characters that have to be read in. Better put everytihing on a single
> line.

Isn't that part of what Gzip compression does automatically? Buffers
out tabs, newlines, etc?


> Oh and don't have variable names that are longer than necessary, it
> all increases the time the file takes to be read, so just use single
> letters for all variable names.

I wasn't sure if that would have much of an impact, but I've already
been at that point ;-) I've also moved images into sprite images.
While the filesize is practically the same, it has cut down on the
number of connections per page load, which has had a noticeable
impact.

Don't think that the sarcasm was lost on me, but I've found that
saving microseconds per page really does have an impact. It's not
uncommon for this site to have over 1,000 processes per second, so I'm
constantly trying to make each process finish faster to prevent
processes from going into the queue.

Now that I've explained why it matters, do you think that including
several PHP files would have a discernible impact?
Re: Including PHP scripts on same server [message #171912 is a reply to message #171745] Fri, 21 January 2011 00:38 Go to previous messageGo to next message
Jo Schulze is currently offline  Jo Schulze
Messages: 15
Registered: January 2011
Karma: 0
Junior Member
jwcarlton wrote:

> I currently have several functions scripted on one page. If I move
> these to several different PHP files and then include them on the
> original page, will this be any slower (or cause more of a server
> load) than having them coded directly on the page?

Not in a significant way.

Normalizing code is highly recommended and supported by PHP, it's a good
idea.
Re: Including PHP scripts on same server [message #171913 is a reply to message #171911] Fri, 21 January 2011 01:50 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 1/20/2011 4:46 PM, jwcarlton wrote:
>> Why does it matter. If you're that concerned about speed of execution,
>> why are you using php in the first place? You should code your site in
>> C.
>
> That's actually a very good question. If I were a better C programmer,
> I probably would :-)
>

Good luck.

>
>> And even if you had a single php file, think of all those newline
>> characters that have to be read in. Better put everytihing on a single
>> line.
>
> Isn't that part of what Gzip compression does automatically? Buffers
> out tabs, newlines, etc?
>

No, it does not. And BTW, it also takes up cpu cycles - which you seem
to be so overly concerned about.

>
>> Oh and don't have variable names that are longer than necessary, it
>> all increases the time the file takes to be read, so just use single
>> letters for all variable names.
>
> I wasn't sure if that would have much of an impact, but I've already
> been at that point ;-) I've also moved images into sprite images.
> While the filesize is practically the same, it has cut down on the
> number of connections per page load, which has had a noticeable
> impact.
>
> Don't think that the sarcasm was lost on me, but I've found that
> saving microseconds per page really does have an impact. It's not
> uncommon for this site to have over 1,000 processes per second, so I'm
> constantly trying to make each process finish faster to prevent
> processes from going into the queue.
>
> Now that I've explained why it matters, do you think that including
> several PHP files would have a discernible impact?

If you're performance is that critical, you need to be looking at
hardware solutions - multiple servers, for instance.

And as Paul said - you should be using C instead of an interpreted language.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: Including PHP scripts on same server [message #171914 is a reply to message #171912] Fri, 21 January 2011 02:28 Go to previous messageGo to next message
jwcarlton is currently offline  jwcarlton
Messages: 76
Registered: December 2010
Karma: 0
Member
On Jan 20, 7:38 pm, Jo Schulze <antis...@feuersee.de> wrote:
> jwcarlton wrote:
>> I currently have several functions scripted on one page. If I move
>> these to several different PHP files and then include them on the
>> original page, will this be any slower (or cause more of a server
>> load) than having them coded directly on the page?
>
> Not in a significant way.
>
> Normalizing code is highly recommended and supported by PHP, it's a good
> idea.

Thanks, Jo.
Re: Including PHP scripts on same server [message #171915 is a reply to message #171913] Fri, 21 January 2011 02:27 Go to previous messageGo to next message
jwcarlton is currently offline  jwcarlton
Messages: 76
Registered: December 2010
Karma: 0
Member
>> Isn't that part of what Gzip compression does automatically? Buffers
>> out tabs, newlines, etc?
>
> No, it does not.  And BTW, it also takes up cpu cycles - which you seem
> to be so overly concerned about.

The CPU is rarely under strain, actually. I have a Quad Intel Xeon CPU
3.20GHz, and rarely have a load that's high enough to be noticed. My
bottleneck seems to be RAM; I just upgraded to 4GB, and will need to
upgrade to 8GB within the next few weeks.

I'm also regularly tweaking the server, due to the number of
processes. My average this week has been over 500 processes, with a
peak of over 1100. I've never professed to know a lot about the server
backend, and I was concerned that having 5 includes would turn in to 5
processes per page load.


> If you're performance is that critical, you need to be looking at
> hardware solutions - multiple servers, for instance.
>
> And as Paul said - you should be using C instead of an interpreted language.

A second server is on my list, but that's a big expense so I'm trying
to push it off as long as I can with code and server config tweaks.

When I rebuild next year, maybe I'll make a focus on working in C. It
doesn't seem to be too different from Perl, anyway, and I coded in
Perl for years before ever touching PHP.
Re: Including PHP scripts on same server [message #171916 is a reply to message #171915] Fri, 21 January 2011 03:08 Go to previous messageGo to next message
The Natural Philosoph is currently offline  The Natural Philosoph
Messages: 993
Registered: September 2010
Karma: 0
Senior Member
jwcarlton wrote:
>>> Isn't that part of what Gzip compression does automatically? Buffers
>>> out tabs, newlines, etc?
>> No, it does not. And BTW, it also takes up cpu cycles - which you seem
>> to be so overly concerned about.
>
> The CPU is rarely under strain, actually. I have a Quad Intel Xeon CPU
> 3.20GHz, and rarely have a load that's high enough to be noticed. My
> bottleneck seems to be RAM; I just upgraded to 4GB, and will need to
> upgrade to 8GB within the next few weeks.
>

That really tells the whole story; since clients are bandwidth limited,
you end up with a lot of processes..whether or not the data comes from
separate files or not is scaarcely an issue.

One way to reduce RAM usage is to create a custom shareable library in
C, and put PHP wrappers on it.

Biggish job.


> I'm also regularly tweaking the server, due to the number of
> processes. My average this week has been over 500 processes, with a
> peak of over 1100. I've never professed to know a lot about the server
> backend, and I was concerned that having 5 includes would turn in to 5
> processes per page load.
>

No. It wont. One process. Probably all of those files are in bug=fered
RAM anyway so prvided you have enough..


>
>> If you're performance is that critical, you need to be looking at
>> hardware solutions - multiple servers, for instance.
>>
>> And as Paul said - you should be using C instead of an interpreted language.
>
> A second server is on my list, but that's a big expense so I'm trying
> to push it off as long as I can with code and server config tweaks.
>

Better to get 64GB of RAM on ONE server. If CPU is not stressed and the
gigabit Ethernet is not stressed.


> When I rebuild next year, maybe I'll make a focus on working in C. It
> doesn't seem to be too different from Perl, anyway, and I coded in
> Perl for years before ever touching PHP.

Its not hard to take procedural PHP and turn it into C..if you have a
PHP library of stuff start with that and wrap it in a custom PHP library.
Re: Including PHP scripts on same server [message #171926 is a reply to message #171911] Fri, 21 January 2011 17:08 Go to previous messageGo to next message
Leonardo Azpurua is currently offline  Leonardo Azpurua
Messages: 46
Registered: December 2010
Karma: 0
Member
"jwcarlton" <jwcarlton(at)gmail(dot)com> escribió en el mensaje
news:5f96a08e-f405-4008-b37e-1fef85b66ecf(at)l24g2000vby(dot)googlegroups(dot)com...
>> Why does it matter. If you're that concerned about speed of
>> execution,
>> why are you using php in the first place? You should code your site
>> in
>> C.
>
> That's actually a very good question. If I were a better C
> programmer,
> I probably would :-)

:-)

I am above anything else a C programmer. In fact, my first approach to
web development was a set of C programs that ran as CGI.

It is fine if you host your own domain, but with many hosting
providers, allowing your own binaries to run is some sort of anathema.

With most OSs, the most consuming operations in file handling are
"opens", so, yes, it is likely that splitting a large file into
several small units will add a significant overhead to your script's
execution time.

But if one compares the development time required to navigate and
maintain a large source file against the time required to open the
specific file with the specific functions that you have to work with,
it is likely that the overall life cycle of your program will improve
by using simpler, smaller units.

"Overhead", with modern equipment and OSs, may be safely neglected
except in the most critical applications.

--
Re: Including PHP scripts on same server [message #171932 is a reply to message #171926] Fri, 21 January 2011 20:18 Go to previous message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 1/21/2011 12:08 PM, Leonardo Azpurua wrote:
>
> "jwcarlton" <jwcarlton(at)gmail(dot)com> escribió en el mensaje
> news:5f96a08e-f405-4008-b37e-1fef85b66ecf(at)l24g2000vby(dot)googlegroups(dot)com...
>>> Why does it matter. If you're that concerned about speed of execution,
>>> why are you using php in the first place? You should code your site in
>>> C.
>>
>> That's actually a very good question. If I were a better C programmer,
>> I probably would :-)
>
> :-)
>
> I am above anything else a C programmer. In fact, my first approach to
> web development was a set of C programs that ran as CGI.
>
> It is fine if you host your own domain, but with many hosting providers,
> allowing your own binaries to run is some sort of anathema.
>
> With most OSs, the most consuming operations in file handling are
> "opens", so, yes, it is likely that splitting a large file into several
> small units will add a significant overhead to your script's execution
> time.
>

That's true in compiled languages, but not so much in interpreted
languages such as PHP. Unlike in compiled languages, the interpreter
spends a fair amount of time parsing the scripts and converting them to
instructions the processor can execute. So the overhead of opening a
file is much smaller than in compiled programs.

Additionally, if the file is accessed quite often, it is probably in the
OS's file buffers already (especially if it is read only), so the
overhead is even less.

Not to say that there isn't overhead in opening a file - but it's a very
small percentage of the total time in PHP scripts. There are better
places to look for improvements.

> But if one compares the development time required to navigate and
> maintain a large source file against the time required to open the
> specific file with the specific functions that you have to work with, it
> is likely that the overall life cycle of your program will improve by
> using simpler, smaller units.
>

Very true.

> "Overhead", with modern equipment and OSs, may be safely neglected
> except in the most critical applications.
>
> --
>

Also quite true.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: ElephantMark - a new simple tool for PHP documentation
Next Topic: hack
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Fri Nov 22 20:52:05 GMT 2024

Total time taken to generate the page: 0.01927 seconds