dcsimg


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 9 of 9

Thread: showing intermediate result from a 'long' PHP script

  1. #1
    Join Date
    Jan 2009
    Posts
    4

    showing intermediate result from a 'long' PHP script

    I've written a PHP application solving (recursively) sudoku's. While probing for the solution, several intermediate stages are formed.

    I'm able (from the server) to generate the output for the intermediate solutions and showing them in sequence in a HTML file (generated by PHP).

    However, I would like to have an iframe or a div or ... being updated (as triggered from the server) and not to have to scroll the entire page.

    As far as I understand AJAX, i wil have to initiate (again and again) from the client to request for data. THis will not work for me: first, the sudoku solver is busy working towards its solution and every time an user demand (click ...) will be necessary to have the HTML file updated.

    I've looked in comet or reverse ajax. I understand an can have this operational by issuing javascript and have it interpreted by the main HTML page. However, I've not the skills to have the proper javascript generated again and again from within the sudoku.php .

    So the question. How to achieve a (kind of ) reverse ajax from a running applications.

    thanks,

  2. #2
    Join Date
    Oct 2005
    Location
    Maady
    Posts
    1,819
    I don't understand exactly what u want, but for the last line of "Reverse AJAX", I know that AJAX request a php to execute some lines of code and maybe getting response back ... the reverse of this operation is sending some data to the php page ... is that what u want to achieve?
    u can send data any time using the GET by formating a proper URL like this:
    someFile.php?data=someData&data2=someData2 ... etc

    if u put this string as the requested URL in ur AJAX object, and in the "someFile.php" u $_GET[] the "data" then u will do something like reversing AJAX ...

    if u r just talking about executing many AJAX operations at the same time, u can simply create new object for each of them ... the browser will manage the rest coz it wont allow more than certain number of connection at the same time but u will finally get the results of all of them ...
    Programmer&Cracker CS
    MyBlog:Blog.Amahdy.com
    MyWebsite:www.Amahdy.com

  3. #3
    Join Date
    Jan 2009
    Posts
    4

    some clarification

    on the remark made by 'Amahdy'.

    I do understand how to send data to an PHP application (GET en POST are common, can also done via SESSSION and maybe some more. So that is not my issue.

    I'm also not talking (I guess) about sending many AJAX invocations to an application. For these many request, each request will have an user invocation (click button) on the client. Not what I want. I want the reverse. The server sending information to the client without frequent request from the client side (This is often called reverse ajax, comet or streaming ajax).

    So, another go on my problem description.
    I've written an app which will take about (say) 5 minutes to perform its task (so invoke the *.php, this script terminates in +- 5 min).
    Whilst waiting for those 5 minutes, I would like on the HTML client-side some information on the process going on in this script. Again no problem, I can send information to the cliens-side and flush() them so the client side will receive the information and this will be displayed.
    HOWEVER, the output will be concatenated and appear in sequence on my screen. This is NOT what I want. I would like to have a part of my screen displaying information about the proces (say intermediate results, progressbar, whatever I would like to report in this *.php app) and have this part of the screen updated as information is send by the server. At the moment I write intermediate Sudoku solutions.

    I can send information to the client-side from a separate script. However I'm not able to have this part of the screen updated (generating javascript on the server application sending it to the client).

    Hopes that this helps.

  4. #4
    Join Date
    Oct 2005
    Location
    Maady
    Posts
    1,819
    OK first answering to ur first line:
    of course I know that u know the GET and POST concept, I haven't even gave u more information about them; I just told u to use the GET concept in ur AJAX request, and the response back will be depending on this GET data ...

    Now for ur assumption of the "5 mins" execution time, I don't know how but the maximum execution time for a PHP script is 30 seconds, so the question is r u sure it will continue the execution for that long ??? my guess is that it may take like 5 mins to response back to ur browser but it will not accept more than 30 seconds execution [unless u have changed this in the php.ini which is not recommended as u may know]

    Finally to the topic, what u need here is a progressbar with something like #% report time, isn't it ?
    well u can use for this something like a javascript timer which will execute every 1 second an AJAX object say to check the size of execution and return with a percent result ... this is not at all heavy, it's even used by Gmail to check if there r new emails in my mailbox, u just need to optimize the requested page to execute very quickly to just return the percent by the fastest way, so that the serve won't get heavy neither the client side ... hope this can help.
    Programmer&Cracker CS
    MyBlog:Blog.Amahdy.com
    MyWebsite:www.Amahdy.com

  5. #5
    Join Date
    Jan 2009
    Posts
    4

    not polling but reporting.

    So, yes i misinterpreted the thinghy about POST and GET.

    In my code, I've stated set_time_limit(30) every time I dive in a new recursion, my total execution time can therefore be longer then the usual 30 seconds.

    The suggestion to have a javascript timer starting a AJAX request a kind of polling. First, not what I intend an secondly I do not see how i can poll information from a still executing script. I want the script report back to me when something peculiar has happened. The script knows and can report, in fact it does. The nasty bit is how to have it displayed in a singel iframe (or with somehting like innerHTML in one page.

    See http://www.jbn.helenparkhurst.net/ph...oku/normal.php to see what my script now returns, intermediate soduku results, not in a single iframe (showing one sudoku (intermediate) result at the time), but a simple dump. This is what I would like to change. This is what I understood 'reverse Ajax', streaming ajax or some other nomenclature.

    Most likely it will come down to have the PHP script making a new page and have somehow javascript events or functions reporting to the browser (flush() for fast events) and have the browser display the correct sudoku table....

    eagerly waiting for the response.

  6. #6
    Join Date
    Oct 2005
    Location
    Maady
    Posts
    1,819
    well in this case, I suggest to divide ur work into separate modules,
    for example in the given page, there are 9 steps, so what u have to do is displaying a loading : 0/9 then execute a "get?step=1"
    when u get response back, the loading will be 1/9 and the step will increase by one for the second step and so forth until the script returns a "finished" and the loader will say "loaded successfully" ...

    another suggestion is writing the progress of ur single script in a sort of database or file, and make another script read the content of this file or database ... here u must make sure to close the database connection after each iteration (or file handler in case of writing to file) .. to let the other script able to read those values ...

    I do understand now ur meaning by a reverse AJAXing, but this is not implementable .. only the client can identify the server not the converse .... which means, only the client can ask the server to give him a data, the server can't identify and inject data by itself to a client; the data should be REQUESTED.
    Programmer&Cracker CS
    MyBlog:Blog.Amahdy.com
    MyWebsite:www.Amahdy.com

  7. #7
    Join Date
    Oct 2005
    Location
    Maady
    Posts
    1,819
    I just got another tricky solution, u don't need to change anything in ur coding now other than making the suduko tables hidden, and at the end of each table a script that increase the loading counter, untill the last table should have after it a script to set the loading finished and change the visibility of tables to visible ... got it ?
    Programmer&Cracker CS
    MyBlog:Blog.Amahdy.com
    MyWebsite:www.Amahdy.com

  8. #8
    Join Date
    Jan 2009
    Posts
    4

    getting somewhere...

    the suggestion was to have my application running in steps. Well that can be achieved, but being a recursive application I have to put a lot of external administration to retrieve where I left the previous time. I wonder even if I can achieve this in PHP (picking up where the previous recursion had been terminated/halted/paused).

    The second suggestion was more promising. Dump the internal results in a (kind of) database and have them retrieve them... Is not what I had in mind, but can be a solution. I will have a try in this direction. Have to decide on a sql database or just flat-file one....

    Final remark on the previous reply:
    Look at http://www.obviously.com/tech_tips/slow_load_technique for a method where the server will send information to the client (after first contact to figure out which client to do).
    Nice app, but assuming the data is from a easy and fast executing script (not mine, deep recursive, and I want to have the intermediate results).

  9. #9
    Join Date
    Oct 2005
    Location
    Maady
    Posts
    1,819
    (picking up where the previous recursion had been terminated/halted/paused)
    it's something to change in the architecture design of ur code, a sample example, a function that takes a "step" as parameter, and depending on this value the script will execute ...

    for the given example link, the server does not identify the client and does not send to it data by itself, actually what happens is that the "frame0" which is hidden keep reloading and send requests to the server to give it back a response.
    Programmer&Cracker CS
    MyBlog:Blog.Amahdy.com
    MyWebsite:www.Amahdy.com

Similar Threads

  1. Removing System Tray shortcuts
    By James Brown in forum VB Classic
    Replies: 8
    Last Post: 03-05-2002, 01:54 PM
  2. Change NT service config (disabled -> enabled)
    By pavel in forum VB Classic
    Replies: 0
    Last Post: 10-17-2001, 08:06 PM
  3. verify local admin
    By Patrick Comeau in forum VB Classic
    Replies: 6
    Last Post: 03-22-2001, 11:50 PM
  4. NT Authentication within VB app
    By Amy in forum VB Classic
    Replies: 10
    Last Post: 12-21-2000, 12:21 AM
  5. Replies: 2
    Last Post: 10-18-2000, 10:50 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center