Question

Run php in background including a "loading" effect

Asked by: ping1234

Dear All,

I have a php popup page which connect db to greb some information, but the process takes time..so I would like to have a animated gif with word "processing ... ..." to tell the user the status.

once the db connection is finished, I will ask this popup page to call a javascript to refresh its parent page and then close itself automatically.

but I found that I the gif usually is not loaded and the browser is closed once the query is finished (the browser status is "pending", seems "hold" as not all component are loaded). so I can't have the "loading" effect that I expected.

so what should I do in this case??

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2004-09-13 at 01:39:20ID21128501
Tags

php

,

background

,

run

Topics

PHP Scripting Language

,

Server Side Includes (SSI)

Participating Experts
6
Points
100
Comments
29

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. GIF ANIM "Restart" and ONLOAD consistency
    Well I'm planning on using GIF ANIM for a small sequence of my webpage. I have JS code which will actually replace one graphic for this GIF ANIM using: document[grfx].src="p/anim.gif"; I am using imagemaps and so there are a few HREFS inside <AREA> tags whic...
  2. Animated GIFs vs JavaScript image swapping
    What are the main differences between Animated GIFs and JavaScript image swapping for the delivery of simple images on the net? also which is best?
  3. Animated Gifs Creation
    How could I create dynamic animated gif?
  4. huver and animated gif
    Hi, I have animated gif as background for huver. If I open new window from the page, gif animation stop ??? Thank you, Valor.
  5. Animated gifs
    Hi, A small question from a total Mac Newby. Can someone point me to a nice (and free, or shareware for a small price) program to create animated gifs (from other pictures, e.g. gifs)? It has to run on OS 9.2 on a G3 machine. Kind regards

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: maundedPosted on 2004-09-13 at 01:49:35ID: 12042154

I have a similar function on one of my sites, I build the page and load the gif first, then run the query, when the query returns its result I use an if statement to do: print ("<META HTTP-EQUIV='refresh' content='1;URL=mypage.php?action=1'>");


 

by: ping1234Posted on 2004-09-13 at 01:54:54ID: 12042182

could you please explain a little on
print ("<META HTTP-EQUIV='refresh' content='1;URL=mypage.php?action=1'>");

??

I don't know whether my query time is not long enough..so the animated gif does not show in my case..please advise..

 

by: maundedPosted on 2004-09-13 at 02:08:40ID: 12042246

Sure, once the query has run it will (should) return a result, for me thats a 1 if the query is successful or a 0 if its not.
I run my query as such:
$result = mssql_query($query);
IF ($result == "1") {      
print ("<META HTTP-EQUIV='refresh' content='$rand;URL=mypage.php?action=1'>");
}
ELSE {
print ("There has been an error sending your data, please contact System Administrator");
exit(); };

The line "print ("<META HTTP-EQUIV='refresh' content='$rand;URL=mypage.php?action=1'>");"
Sends the browser to another page which prints the results of the query. Otherwise it just outputs an error message
Can you possibly post your code?

 

by: ping1234Posted on 2004-09-13 at 02:30:45ID: 12042345

the query that I have to execute...can said to be a "small program"..it includes several process...and some of them related to pop3  server connection..

and the page ordering should be

main.php -> onLoad -> then call popup -> popup.php execute the "small program that I mention and at the same time would like to have the loading effect (but not successful now..) -> once the "program" is finished -> call the parent page to refresh and close itself

 

by: maundedPosted on 2004-09-13 at 02:37:25ID: 12042388

OK, I think I understand you.
In the popup.php, build the html first, then call the small program, PHP will build the page, then run your query, then when that query is done, print the http-refresh.

 

by: ping1234Posted on 2004-09-13 at 02:44:04ID: 12042428

thanks,

but..
this refresh statement refresh do not refresh the parent page in my case?

so I use

echo("<script language=\"Javascript\">");
echo("window.opener.location.reload();");
echo("self.close();");
echo("</script>");

actually I the animated gif code is already located first, and the php code follows..but I still can't have the loading effect..

 

by: ZylochPosted on 2004-09-13 at 02:46:09ID: 12042439

Hi

It should reload, but it could depend on what browser you're using.

Try using
window.opener.location=window.opener.location.href;
instead.

Regards,
Zyloch

 

by: fetchmasterPosted on 2004-09-13 at 02:49:29ID: 12042449

instead of meta refresh of the pop up, you can directly close the window just after refreshing the main.php page. its something like this:

popup.php
<?php
//your application code goes here........


//Now execution complete.....
?>
<script>
opener.document.location.reload(true);
window.close();
</script>

 

by: ping1234Posted on 2004-09-13 at 02:53:00ID: 12042472

the reload part is ok..I just can't get the "loading" effect that I expected..

 

by: ZylochPosted on 2004-09-13 at 02:54:47ID: 12042478

The main window is having the loading effect?

 

by: ping1234Posted on 2004-09-13 at 03:00:17ID: 12042505

no, the popup one..please check pervious message..

 

by: ZylochPosted on 2004-09-13 at 03:03:20ID: 12042521

Ah, I see. Try outputting the image without using PHP, something like:

<img src="processing.gif">
<?php
//Your processiong code
?>

if you aren't doing so already. It may not work because PHP may totally be processed first, but it's possible to try.

 

by: maundedPosted on 2004-09-13 at 03:03:33ID: 12042523

Does the page load at all before it runs the query?

 

by: ping1234Posted on 2004-09-13 at 03:07:58ID: 12042544

if I get the query/program commented, I can see my "processing ... ..." animated gif.

but if code are executed, I can just see a pending browser and then refresh the parent window and close itself.

 

by: ZylochPosted on 2004-09-13 at 03:14:38ID: 12042566

Most likely because the PHP executes itself totally before outputting to the browser.

You can always try sending a chunked transfer:

header("Transfer-Encoding: chunked");

 

by: maundedPosted on 2004-09-13 at 03:15:05ID: 12042569

I output the html before doing anything in PHP

 

by: ping1234Posted on 2004-09-13 at 03:46:55ID: 12042725

I have already output html before the execution of php...

finially..I've got a solution for my problem.
main.php -> onLoad -> then call popup -> popup.php execute the "small program that I mention and at the same time would like to have the loading effect  -> once the "program" is finished -> call the parent page to refresh and close itself

in the popup.php, I use frameset..top frame contains only a "processing....." gif and a hidden frame process the code, once the code is processed, it call the parent 's opener to refresh itself and then call parent to close.

Thanks for all of your help!

 

by: RQuadlingPosted on 2004-09-13 at 05:39:15ID: 12043270

Try something like this ...

<html>
<head>
<title>KPI Production</title>
<link title="KPI Style Sheet" rel="stylesheet" href="kpi_css.php">
</head>
<body>
<div class="MainDIV">
      <a href="/"><img class="LogoIMG" src="./images/bandvulc_kpi_logo.gif" alt="Bandvulc Tyres KPI Production" /></a>
      <hr class="MainHR" />
</div>
<div class="PleaseWaitDIV" id="pleasewait">
      <h2 class="PleaseWaitH2">
            Please wait - generating results
      </h2>
      This may take some time.<br />
      If you want to abort the current operation, then click <a class="PleaseWaitA" href="/index.php">here</a> to return to the main menu.
      <br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
</div>
<?php
flush();
.....
// Include your PHP code here, but make sure it only generates a $sOutput.
?>
<script language="JavaScript"><!--
pleasewait.style.display = 'none';
document.body.style.cursor = 'auto';
//--></script>
$sOutput
END_HTML;
?>
</body>
</html>

I use this for all my internal apps.

The PleaseWait div shows whilst the page is being generated (normally involves getting data from a DB, sorting it out, building tables or a PDF, etc, and can take several seconds or even minutes if the request is a big analysis). The PHP code builds a text variable for the output (i.e. functions NEVER echo/print, only return) and the main app builds up the output from the functions). I COULD have used output buffering, maybe. But I didn't.

When the output is ready, the javascript "hides" the pleasewait div and then shows the real div.

Also, the cursor is changed from "busy" to "ready".

Only tested on Windows, IE6.

The please wait div COULD include any sort of output you want. An image which could be a flash thing which looks at a counter the main php code is generating maybe, to give you some sort of real time feedback.

Regards,

Richard.

 

by: m1ckey_GPosted on 2004-09-13 at 06:28:52ID: 12043701

Yo can try using output control.

<?php
ob_start ();
echo ('Your HTML here');
ob_flush ();

// Your query here

 

by: SashoPosted on 2004-09-13 at 16:46:37ID: 12049927

This is what I do on my pages:

<html>
<head>
      <script type="text/javascript" language="javascript">
      function swapContent(divID, srcDivID)
      {
              document.getElementById(divID).style.display='none';
              document.innerHTML = document.getElementById(srcDivID).innerHTML;
      }
      </script>
</head>
<body marginheight="0" marginwidth="0" leftmargin="0" topmargin="0">
      <DIV id='Wait_Text' STYLE="position:absolute; top:200;left:200; border:none thin gray;z-index:300">
            <table width="*" cellpadding="3" cellspacing="1" border="0" class="forumline">
                  <td class="Open"><h1>Please wait while the data is being processed...</h1.</td>
            </table>
      </DIV>
      <?
      flush();
      ?>
      <div id='Good' 'display:none;z-index:200'>
            <?
            //Your PHP goes here
            sleep(10);
            print("PHP is done!");
            //---------------------
            ?>
      </div>
      <SCRIPT LANGUAGE="JavaScript"><!--swapContent('Wait_Text','Good');//--></SCRIPT>
</body>
</html>

 

by: SashoPosted on 2004-09-13 at 16:54:19ID: 12049979

Sorry my last comment had a cut and paste error which made it wrong. here is the code which I tested and works:

<html>
<head>
<script type="text/javascript" language="javascript">
function swapContent(divID, srcDivID)
{
  document.getElementById(divID).style.display='none';
  document.innerHTML = document.getElementById(srcDivID).innerHTML;
}
</script>
</head>
<body marginheight="0" marginwidth="0" leftmargin="0" topmargin="0">
<DIV id='Wait_Text' STYLE="position:absolute; top:200;left:200; border:none thin gray;z-index:300">
<table width="*" cellpadding="3" cellspacing="1" border="0" class="forumline">
<td class="Open"><h1>Please wait while the data is being processed...</h1.</td>
</table>
</DIV>
<?
flush();
?>
<div id='Good' 'display:none;z-index:200'>
<?
//Your PHP goes here
sleep(3);
print("Php is done");
?>
</div>
<SCRIPT LANGUAGE="JavaScript"><!--
      swapContent('Wait_Text','Good');
//--></SCRIPT>
</body>
</html>

 

by: fetchmasterPosted on 2004-09-13 at 21:35:11ID: 12051335

Sasho,


<div id='Good' 'display:none;z-index:200'>
should be
<div id='Good' style='display:none;z-index:200'>
i think?

 

by: RQuadlingPosted on 2004-09-14 at 00:01:03ID: 12051868

Sasho and my code do pretty much the same thing. Show a "Please wait" sort of thing up front and then hide it when the results come through.

BTW, the JS code of document.getElementByID(), is this necessary? Why not simply elementID.?

Richard.

 

by: SashoPosted on 2004-09-14 at 08:51:31ID: 12055910

Sorry RQ I read many of the initial comments and they seemed to be heading in a different direction, with multiple files, I did not notice your post.

Indeed my implementation is very similar to what you posted.



 

by: RQuadlingPosted on 2004-11-04 at 03:34:06ID: 12492422

All good answers. Split for all would be nice.

 

by: SashoPosted on 2004-11-04 at 07:26:03ID: 12494407

I agree

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...