Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #3947 > unrolled thread
| Started by | "Jeff Gaines" <jgaines_newsid@yahoo.co.uk> |
|---|---|
| First post | 2011-11-27 12:01 +0000 |
| Last post | 2011-11-28 11:07 +0000 |
| Articles | 5 — 4 participants |
Back to article view | Back to comp.lang.php
Order/Timing of Execution of PHP "Jeff Gaines" <jgaines_newsid@yahoo.co.uk> - 2011-11-27 12:01 +0000
Re: Order/Timing of Execution of PHP Denis McMahon <denismfmcmahon@gmail.com> - 2011-11-27 14:14 +0000
Re: Order/Timing of Execution of PHP Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-11-28 01:53 +0100
Re: Order/Timing of Execution of PHP Jerry Stuckle <jstucklex@attglobal.net> - 2011-11-27 09:43 -0500
Re: Order/Timing of Execution of PHP "Jeff Gaines" <jgaines_newsid@yahoo.co.uk> - 2011-11-28 11:07 +0000
| From | "Jeff Gaines" <jgaines_newsid@yahoo.co.uk> |
|---|---|
| Date | 2011-11-27 12:01 +0000 |
| Subject | Order/Timing of Execution of PHP |
| Message-ID | <xn0hm3pyv2tnoe7000@news.individual.net> |
A comment in this group made me look at a website again. It has a couple
of 'photo albums on it and when the visitor clicks on either of the album
pages it uses
imagecreatefromjpeg/imagecreatetruecolor/imagecopyresized/imagejpeg to
create thumbnails from the full sized images with links to them.
I decided that I should create the thumbnails locally and then upload them
to save visitors wondering why there was a delay when visiting the pages.
I use the following code:
<div id="content">
<article>
<section>
<br />
<br />
<p>
Select Album To Create
<br />
</p>
<hr>
<a href="?run=all">All</a>
<br>
<a href="?run=album">Album Only</a>
<br>
<a href="?run=george">George\'s Album Only</a>
<br />
<br />
<?php
if (isset($_GET['run']))
$linkchoice=$_GET['run'];
else $linkchoice='';
switch($linkchoice)
{
case 'album' :
echo('<b>Creating Thumbnails For Album...</b>');
echo('<br /><br />');
createalbum();
echo ('Album Thumbs Created');
echo ('<br /><br />');
break;
case 'george' :
echo('<b>Creating Thumbnails For George\'s Album...</b>');
echo ('<br /><br />');
creategeorge();
echo ('George\'s Thumbs Created');
echo ('<br /><br />');
break;
}
?>
</section>
</article>
</div>
What this does is show links for 2 options and then re-post the page.
It works but doesn't echo 'Creating Thumbnails' etc. until it has called
the function and returned from it.
Is there a way to get these statements echoed before it calls the function
or is this just the way php/server side functions work, in which case
perhaps I should use Java?
--
Jeff Gaines Wiltshire UK
Indecision is the key to flexibility
[toc] | [next] | [standalone]
| From | Denis McMahon <denismfmcmahon@gmail.com> |
|---|---|
| Date | 2011-11-27 14:14 +0000 |
| Message-ID | <4ed245c3$0$29369$a8266bb1@newsreader.readnews.com> |
| In reply to | #3947 |
On Sun, 27 Nov 2011 12:01:47 +0000, Jeff Gaines wrote: > It works but doesn't echo 'Creating Thumbnails' etc. until it has called > the function and returned from it. Possibly caused by buffering on the server, or even the client waiting to render output until it's able to decide what is to be rendered and how? I think it's better to do all the processing first, and then send the web page afterwards, rather then send html in dribs and drabs while you're doing the processing. This isn't the way I used to think, but it has advantages. For example, you can trap and react to errors in the processing by issuing http error headers, which you can't do if you've started output. Rgds Denis McMahon
[toc] | [prev] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2011-11-28 01:53 +0100 |
| Message-ID | <7115120.c4VAs2iPgL@PointedEars.de> |
| In reply to | #3948 |
Denis McMahon wrote: > On Sun, 27 Nov 2011 12:01:47 +0000, Jeff Gaines wrote: >> It works but doesn't echo 'Creating Thumbnails' etc. until it has called >> the function and returned from it. > > Possibly caused by buffering on the server, or even the client waiting to > render output until it's able to decide what is to be rendered and how? > > I think it's better to do all the processing first, and then send the web > page afterwards, rather then send html in dribs and drabs while you're > doing the processing. This isn't the way I used to think, but it has > advantages. For example, you can trap and react to errors in the > processing by issuing http error headers, which you can't do if you've > started output. The disadvantage of it is that the user would have to wait for all PHP processing to finish before seeing any content. I have recently heard of an approach to mitigate, even solve, this problem, but I do not remember how it worked. PointedEars -- > If you get a bunch of authors […] that state the same "best practices" > in any programming language, then you can bet who is wrong or right... Not with javascript. Nonsense propagates like wildfire in this field. -- Richard Cornford, comp.lang.javascript, 2011-11-14
[toc] | [prev] | [next] | [standalone]
| From | Jerry Stuckle <jstucklex@attglobal.net> |
|---|---|
| Date | 2011-11-27 09:43 -0500 |
| Message-ID | <jatibg$ihe$1@dont-email.me> |
| In reply to | #3947 |
On 11/27/2011 7:01 AM, Jeff Gaines wrote:
>
> A comment in this group made me look at a website again. It has a couple
> of 'photo albums on it and when the visitor clicks on either of the
> album pages it uses
> imagecreatefromjpeg/imagecreatetruecolor/imagecopyresized/imagejpeg to
> create thumbnails from the full sized images with links to them.
>
> I decided that I should create the thumbnails locally and then upload
> them to save visitors wondering why there was a delay when visiting the
> pages. I use the following code:
>
> <div id="content">
> <article>
> <section>
> <br />
> <br />
> <p>
> Select Album To Create
> <br />
> </p>
>
> <hr>
> <a href="?run=all">All</a>
> <br>
> <a href="?run=album">Album Only</a>
> <br>
> <a href="?run=george">George\'s Album Only</a>
> <br />
> <br />
>
> <?php
>
> if (isset($_GET['run']))
> $linkchoice=$_GET['run'];
> else $linkchoice='';
>
> switch($linkchoice)
> {
> case 'album' :
> echo('<b>Creating Thumbnails For Album...</b>');
> echo('<br /><br />');
> createalbum();
> echo ('Album Thumbs Created');
> echo ('<br /><br />');
> break;
>
> case 'george' :
> echo('<b>Creating Thumbnails For George\'s Album...</b>');
> echo ('<br /><br />');
> creategeorge();
> echo ('George\'s Thumbs Created');
> echo ('<br /><br />');
> break;
> }
> ?>
>
> </section>
> </article>
> </div>
>
> What this does is show links for 2 options and then re-post the page.
>
> It works but doesn't echo 'Creating Thumbnails' etc. until it has called
> the function and returned from it.
>
> Is there a way to get these statements echoed before it calls the
> function or is this just the way php/server side functions work, in
> which case perhaps I should use Java?
>
No guarantee as long as you're using HTTP.
When you output something to the client, it goes in a PHP buffer. Once
the buffer fills up, the contents are forwarded on.
Now - you can use flush() to force the PHP buffer to be emptied.
However, it can still be buffered by the server, depending on the server
and its settings. And once it has been sent, the client may or may not
display the data immediately, depending on the client and its settings.
Changing to java won't help with the server and client settings, unless
you have an applet running on the client and using other than http (i.e.
another tcp/ip socket) to perform the communications.
But then I also wouldn't do this online - I'd just have a CLI script
which does them all, logging results to a file. Then as new pictures
are uploaded, create the thumbnails right then. It doesn't take that long.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
[toc] | [prev] | [next] | [standalone]
| From | "Jeff Gaines" <jgaines_newsid@yahoo.co.uk> |
|---|---|
| Date | 2011-11-28 11:07 +0000 |
| Message-ID | <xn0hm53394757ku002@news.individual.net> |
| In reply to | #3949 |
On 27/11/2011 in message <jatibg$ihe$1@dont-email.me> Jerry Stuckle wrote: >But then I also wouldn't do this online - I'd just have a CLI script which >does them all, logging results to a file. Then as new pictures are >uploaded, create the thumbnails right then. It doesn't take that long. Many thanks, Jerry. I have never used php at the command line but it seems an ideal solution. -- Jeff Gaines Wiltshire UK There are 3 types of people in this world. Those who can count, and those who can't.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.php
csiph-web