Results 1 to 19 of 19

Thread: Continued Code Execution After Page Output

  1. #1

    Thread Starter
    Addicted Member OsirisX's Avatar
    Join Date
    May 2002
    Location
    Montgomery, AL
    Posts
    132

    Continued Code Execution After Page Output

    I'd like to output a page and disconnect from the user, so that it won't act like it's still loading, then perform a simple database transaction. But this transaction uses a remote server so it will hold up web page loading. I'd like to release the browser and continue to execute code.
    Thank you,
    James
    --OsirisX
    AIM, Yahoo: OsirisX11
    ICQ: 56697525
    MSN: [email protected]

  2. #2
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    then you have to do it before you load the page. other than that there is no way to release the browser.

  3. #3
    New Member
    Join Date
    Sep 2002
    Location
    The World of Xeen
    Posts
    14
    Perhaps you could use some javascript in your HTML to define a function which stops the browser loading the page. Then when you are ready just
    PHP Code:
    echo "<script language='javascript'> <!-- call the stop function here --></script>"
    to stop loading.

    I'm no expert, it may not be possible. Just an idea!

  4. #4

    Thread Starter
    Addicted Member OsirisX's Avatar
    Join Date
    May 2002
    Location
    Montgomery, AL
    Posts
    132
    I think that if the page is stopped the code will stop as well.
    --OsirisX
    AIM, Yahoo: OsirisX11
    ICQ: 56697525
    MSN: [email protected]

  5. #5
    New Member
    Join Date
    Sep 2002
    Location
    The World of Xeen
    Posts
    14
    Not always.

    I had a do { } while() loop that pulled files from a database and then wrote them to the hard drive. I could stop the page in my browser, but using the Windows Task Manager revealed that php.exe was still running and mysql was still working hard in the background...... so the script kept running even though I'd hit stop. I assume this is because it was in a do {} while loop though...

    Matt

  6. #6

    Thread Starter
    Addicted Member OsirisX's Avatar
    Join Date
    May 2002
    Location
    Montgomery, AL
    Posts
    132
    thanks matt. unfortuanatatley I can't use javascript in this case.
    the target parser (AIM's infobrowser) does not support it.
    --OsirisX
    AIM, Yahoo: OsirisX11
    ICQ: 56697525
    MSN: [email protected]

  7. #7
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    Originally posted by MattT
    Not always.

    I had a do { } while() loop that pulled files from a database and then wrote them to the hard drive. I could stop the page in my browser, but using the Windows Task Manager revealed that php.exe was still running and mysql was still working hard in the background...... so the script kept running even though I'd hit stop. I assume this is because it was in a do {} while loop though...

    Matt
    if you stop the browser what is teh php.exe doing then if it can't display the info. if you stop the browser, the code stops.

    just because you stop the browser and you could still see the processes still going doesn't mean anything.

  8. #8

    Thread Starter
    Addicted Member OsirisX's Avatar
    Join Date
    May 2002
    Location
    Montgomery, AL
    Posts
    132
    I think an acceptable solution for what I want to do what be to write a secondary php script and have the primary php exec a batch file that runs the secondary one.
    --OsirisX
    AIM, Yahoo: OsirisX11
    ICQ: 56697525
    MSN: [email protected]

  9. #9
    New Member
    Join Date
    Sep 2002
    Location
    The World of Xeen
    Posts
    14
    Originally posted by phpman
    if you stop the browser what is teh php.exe doing then if it can't display the info. if you stop the browser, the code stops.

    just because you stop the browser and you could still see the processes still going doesn't mean anything.
    No, you're wrong. The script goes through every file in a folder, reads it's contents, writes the file's contents to a MySQL database, then deletes the file. I'm running an Apache server on a WinXP box. I browse to http://localhost/parc/import.php (the script). It lists the files names as they are imported into the database and deleted.

    I press stop in my browser. The browser "stops" .. ie no more files are listed.

    I press Ctrl-Alt-Delete. "php.exe" is still running and using 2% of the CPU time. "mysql-nt.exe" is running and using between 25%-75% of the CPU time.

    I go to the folder from which the files are being imported & deleted. Sure enough, they are disappearing one by one.

    No offense, but I think I know what I'm talking about here.

    The "code" has not stopped. The output has. I can forward you the script if you'd care to check it out yourself. The php process stops and disappears from my task list when the "code" stops.

  10. #10

    Thread Starter
    Addicted Member OsirisX's Avatar
    Join Date
    May 2002
    Location
    Montgomery, AL
    Posts
    132
    Now now, play nice children.
    --OsirisX
    AIM, Yahoo: OsirisX11
    ICQ: 56697525
    MSN: [email protected]

  11. #11
    You would have to write another script which would be called after the page is displayed.

    Using something like <img src="database.php?blah=3" alt="" />

    and have that file query the database, and then return either an image you want to display, or return a blank 1x1 transparent gif.

  12. #12
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by cyborg from dh
    You would have to write another script which would be called after the page is displayed.

    Using something like <img src="database.php?blah=3" alt="" />

    and have that file query the database, and then return either an image you want to display, or return a blank 1x1 transparent gif.
    That wouldn't work...
    My evil laugh has a squeak in it.

    kristopherwilson.com

  13. #13
    New Member
    Join Date
    Sep 2002
    Location
    The World of Xeen
    Posts
    14
    Actually, it would I think. The page displayed would contain an image like cyborg said, and this image would be generated by the second script. (Confusing!)

    The first script contains <img src="database.php?a=1&etc."> ... so all this script does really is display some output. The second script (database.php) would actually *perform* the database operation and return an image (with the proper HTML headers)depending upon whether the transaction succeeds or fails. ie. a tick and the words "This operation has completed successfully" as a GIF, or a big red cross and an error description (it could be dynamically generated depending on your PHP compile options.)

    Or am *I* confused? I've done this whole dynamic image thing before, never with a database query involved, but it seems fairly straight forward.

  14. #14
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    if you run this

    <img src="database.php?a=1&etc.">

    in a page it will run the page and then hit this image tag and run it, ONCE the tag is done it continues with the rest of the page.

    there is a funtion in php that will continue code after the page has fully loaded. it is call register_shutdown_funtion()

    this code will run a function AFTER the page is fully loaded.

  15. #15

    Thread Starter
    Addicted Member OsirisX's Avatar
    Join Date
    May 2002
    Location
    Montgomery, AL
    Posts
    132
    When I started this thread, my goal was to simply cut off the connection with the browser, telling them everything was ok and to stop loading, etc. And then perform a simple DB transaction or delete a file or probe their ports, whatever. Is there not a simple function to end output? Like... ob_endclean or something?
    --OsirisX
    AIM, Yahoo: OsirisX11
    ICQ: 56697525
    MSN: [email protected]

  16. #16
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    Originally posted by phpman
    there is a funtion in php that will continue code after the page has fully loaded. it is call register_shutdown_funtion()

    this code will run a function AFTER the page is fully loaded.

  17. #17

    Thread Starter
    Addicted Member OsirisX's Avatar
    Join Date
    May 2002
    Location
    Montgomery, AL
    Posts
    132
    tight, thanks!
    --OsirisX
    AIM, Yahoo: OsirisX11
    ICQ: 56697525
    MSN: [email protected]

  18. #18
    New Member
    Join Date
    Sep 2002
    Location
    The World of Xeen
    Posts
    14
    1) HTML page, or whatever.. this is the HTML form.

    PHP Code:
    ...
    <
    FORM ACTION="SCRIPT1.PHP">
    <
    input type='text' name='thing'>
    etc
    etc
    </FORM>
    ... 

    2) script1.php: here you process some of the data to generate the output page - EXCEPT the part that says whether the database process succeeded. In the script you have something like:

    PHP Code:
    <IMG src="script2.php?thing=var1&etc=etc..."
    or
    PHP Code:
    <IFRAME ......> 
    The URL for this image or page would be dynamically generated by script1 from the variables passed to it.

    3) script2.php: This performs the database action and returns the proper HTML headers (eg for a GIF image) and then returns a gif image indicating either success or failure.

    This way the page loads, leaving only one image or section (IFRAME is supported by internet explorer only) unloaded.. which is then loaded after the database transaction is complete (ie the second script runs)

    It's a bit confusing but I dont think I can better articulate it ;-)

  19. #19

    Thread Starter
    Addicted Member OsirisX's Avatar
    Join Date
    May 2002
    Location
    Montgomery, AL
    Posts
    132
    I think this method could be very insecure. Anyone can request the proper url and do whatever they like.
    --OsirisX
    AIM, Yahoo: OsirisX11
    ICQ: 56697525
    MSN: [email protected]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width