The problem
My initial php script looked something like this:
echo "text"; // display text
echo "<img src='displaypic.php'>"; // display pic
echo "text"; // display text
I observed that when loading the page the text was displayed first (after 1 or 2 seconds) then the pics (it took a bit longer). That was pretty fine because users were never in front of a blank page.
Later I added a script for displaying a flash pie chart (found the script on Open Flash Chart):
echo "text"; // display text
echo "<img src='displaypic.php'>"; // display pic
echo "text"; // display text
include 'piechart.php'; // display flash chart
It works fine but... all visual content (text, pics, chart) is displayed at once. The problem is that it takes about 10 sec. to load and I think it is just too long.
What I would like to do
Ideally I would like to have text displayed first, followed by pics and chart so users are not in front of a blank page. Is there a simple way to do that? Thanks.
Your question isn't related to PHP execution. Because php usually compiles and executed on server side before your server sends any data to client side. So when you see any result on your webpage it means your php script already completely finished running.
On the other hand displaying some elements first related to how a browser renders html, javascript and css so you can find a solution in those. Changing your table/div etc structure , putting include files to correct positions will make a change about your expected result. But don't forget It can also varies depending on what browser you are using while testing your site.
Related
This is such a bizarre thing that even just typing in the title makes me question my own sanity. Anyway, I'm trying to figure out why my reports are taking so long to load and I've discovered that Chrome is loading an image of my page, after the page has finished loading. But don't take my word for it, check this screenshot from dev tools.
You can see that there are two instances of report.test.php being loaded. The first one is a document and the second one is an img. (You can tell by the icon and also by filtering the list on those two types).
So in this example the report is small and loads about 15 rows of data and renders them in an HTML table. This is done after 710 ms (in this example) and it all looks good except that the favicon in the browser tab keeps spinning for another 808 ms while that img loads. Not a huge deal on a small report like this one but if you load a lot more data that takes, for example, 6 seconds to load, then this second image also takes an additional 6 seconds to load for a total of 12 and that's a big deal.
Now as I said, when the document is finished loading I can see that the HTML has finished rendering so I can essentially use the report and ignore the spinning favicon, but this causes problems if I try to load another report, in another tab, while that favicon is still spinning. It gets jammed up and basically brings everything to a grinding halt and it's all bad. Bottom line, I need to stop this from happening.
So what is this img version of my report? Why is it there and can I prevent it?
Turns out chrome was generating its own image because I told it to use a blank background image in my body style.
Background
I had added background:url('') to the body tag of the reports page.
<body style="background:url('')">
I did this because the stylesheet I was using at the time added a background image, which I wanted for every other page in my app but not the reports page, so this was my way of overriding the style sheet.
Solution
Anyway, apparently when you submit a blank string as a background image chrome then generates its own image and it does so by making an image of the entire page, and the more HTML on the page the longer it takes to generate this image.
The solution is to not pass in a blank string to background:url.
I have a webpage with 2 tabs, one is for uploading data and second is for showing the result. The first tab is a form which is redirected to a php file (upload.php) on submit.
I want to upload data in first tab using php and then without redirecting to another page,go to the next tabb and see the result there.
Can anyone tell me if this is possible to run a php file on the background? I'm so new in php programming and didn't find anything helpful searching my question.
By default when a webpage is loaded, images are loaded one single time for each image. If you have 5 instances of the same image on a page, that image is loaded once, and then used in all 5 places seemingly from the cache of the first image load.
What I want to do is have a single image displayed 5 times on a page, and each time the images is called have it re-loaded.
The reason for this is I have an image that is called from a database and each time the image is called it loads a different picture. Now this works perfectly when refeshing the page, but not when the image is loaded multiple times on the same page.
For example if I put the following into a webpage:
<img src='http://bannerpillar.com/u/viraladmin.jpg'>
The image loads perfectly. If I reload the page, a different picture is displayed for each time the page reloads. However if I add the image to a page in 2 different locations, the same one picture is displayed from both locations.
How can I make it so the image is refreshed every time it is called on a page? Is that possible?
Try adding something to the end of the file reference, like this:
<img src='http://bannerpillar.com/u/viraladmin.jpg?<?=rand(11111,99999)?>'>
The browser will think each image is unique and load each one separately rather than using the image from cache.
You can find a tutorial on this exact question here:
http://www.marcofolio.net/webdesign/php_random_image_rotation.html
Basically, in the src, you call a php file. The php file loads a filename from a directory of images.
For your case, you would need to write some logic to offset the database return, so this becomes a mysql question as well?
If you wanted the markup to call for an image file, you could redirect using a .htaccess rewriterule
Random no. generetion can be a good option.
but more better if you load those images serially i.e. one after another
n u can use looping for that.
Add a ?rand= to the image url.
<img src='http://bannerpillar.com/u/viraladmin.jpg?rand=<?php echo rand(100000,999999); ?>'>
I am using FPDF to create a pdf document in an iFrame... During the pdf creation the script communicates and gets a lot of data from the server, and then I would like to display a progress bar.. That is why I have put the php generator in an iFrame.. then my plan was that the php script could send the looped data to the parent window..
e.g. every time a loop is made it says $count++;, then I know how many loops it has gone through, and I already know that it is going to limit the rows to the first 200 rows.. Then I would like to display the looped data in the parent widow like so: $count of §goal has been generated successfully!.. At the moment I am using jQuery, where I ask the php to echo some jQuery script every time a loop is made to display the results like so window.parent.count($count, $goal);.. Count in the parent winodw and it actually works well until the PDF has to be shown.. then I get an error message that tells me that the script is unable to display the PDF because the page already has outputted data..
Does anybody know how to make the PHP to send the data to the parent window, so I prevet the using of echo?
Sorry for my bad english.. if wished I can try to upload my script later for you to see...
I do it a bit differently...
I also wrote an application in which the PDF generator needs to fetch a rather large amount of data, so the generation takes a few seconds.
I use jQuery to fetch a php-page in the background. During this download, the screen turns gray and displays a classic "please wait"-circle. The only output that the php-file generates is an "OK" echo, together with a file link, when the generation has been completed. Instead of displaying the file inline, I save the PDF in a folder ($pdf->Output('filename.pdf','S')) and offer it as a download using the provided link and the jQuery-callback.
I hope you understand what I mean. Maybe this thought will help you a bit further.
EDIT: Don't know if this will work, but I just thought of it...
You could save the file and output the filename. Using jQuery, you could then refresh the contents of the iframe to fetch a page in which you display the already saved PDF inline...
I have standard text links which all say "Full View". When clicked these links send out php in this form: http://mysite.com/fullview.php?myimage=30
Basically there's thumbnailed images and text links that say full view. I'd like for fullview.php to capture the myimage variable, and display it as a full sized image. Meaning, a blank page (fullview.php) displaying the image. Sounds likes javascript to me.
How do you put the javascript into fullview.php to capture the variable and display it as a full sized image?
Thanks for any help,
Darrell
php is server side script
javascript is client side script
so displaying a web page to a user first is executed php and result is send to client. After he receive it then javascript is executed
HTH
Ivo Stoykov
You just need to read the query parameters. In fullview.php you can use
$myimage = $_GET['myimage']; to capture this variable. And then can use it accordingly.