|
Posted by d on 09/30/22 11:41
"Simon" <spambucket@example.com> wrote in message
news:46re0iFcj4evU1@individual.net...
> Hi,
>
> Sorry for the cross posting, but I think it applies to both languages.
>
> As we all know, JavaScript is client side and php is server side, (the php
> code is 'allowed' to do stuff on the server that JavaScript cannot).
> The problem with php is that it timeout after a while, (and the user also
> has no clue as to what is going on for a long time).
> I need to run a script on the server that could take a very long time.
>
> So what I was thinking is mixing both JavaScript and PHP
> Something like,
>
> <script>
> var endvalue = 1000; /* some number that the server can calculate
> quickly */
> var i = 0
> while (i<=endvalue)
> {
> /**
> call a php file that will do some work
> somefunction.php?someNumber=i
> */
> }
> </script>
>
> That way the server does the work, while the client keeps it going.
> Ideally I would also get a return value/string from the php script.
>
> How could I achieve something like that?
>
> Many thanks in advance.
>
> Simon
I've done something similar to this myself :)
I found the best way to do it is to have your lengthy PHP script running in
a hidden iframe, occasionally spitting out chunks of javascript (in complete
<script> tags), and flushing the output after each tag is written. The
javascript can update a textual display, or a progress bar or whatever, on
the document holding the iframe. It's really simple to use, and very
effective.
dave
[Back to original message]
|