exit() Needed at end?

Discussion in 'PHP' started by hovesh07, Feb 20, 2009.

  1. #1
    Hi All,
    I looked at a list of running processes on my server, and some have been running for a while. The script in question should build/present a web page, and that's it.

    Should all my scripts end with an "exit(0);" if all is OK?

    Thanks!
     
    hovesh07, Feb 20, 2009 IP
  2. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #2
    you can, but it's not a requirement for PHP. But it could speed up your sites a little!
     
    EricBruggema, Feb 24, 2009 IP
  3. ActiveFrost

    ActiveFrost Notable Member

    Messages:
    2,072
    Likes Received:
    63
    Best Answers:
    3
    Trophy Points:
    245
    #3
    exit function is only for breaking a script execution in the place where it should not break ( as an example, if loops with some verification ). No need to add it at the end of your script !
     
    ActiveFrost, Feb 24, 2009 IP
  4. ads2help

    ads2help Peon

    Messages:
    2,142
    Likes Received:
    67
    Best Answers:
    1
    Trophy Points:
    0
    #4
    I don't think it's neccessary. And I am not sure if it does speed up the loading speed.

    - ads2help
     
    ads2help, Feb 24, 2009 IP
  5. projectshifter

    projectshifter Peon

    Messages:
    394
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #5
    That's really not accurate at all. You shouldn't need to exit PHP unless you're sending a header(location) or intentionally trying to end the script before the last few lines of code. If your script is still running after a while, you've either got it locked up in a while loop, or something is going wrong because it should be exiting as soon as the last line of code gets read. Maybe you should run the code in a browser, or in a console and watch what's going on with it.
     
    projectshifter, Feb 24, 2009 IP
  6. SmallPotatoes

    SmallPotatoes Peon

    Messages:
    1,321
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Using exit at the end of your script has no effect whatsoever. It only has an effect if you call it before it would otherwise end.
     
    SmallPotatoes, Feb 24, 2009 IP
  7. NetworkTown.Net

    NetworkTown.Net Well-Known Member

    Messages:
    2,022
    Likes Received:
    28
    Best Answers:
    0
    Trophy Points:
    165
    #7
    There is no need to put exit() function at the end of your pages/scripts. It is used in functions/classes/coding to exit the script normally used under if,else,while statments.
     
    NetworkTown.Net, Feb 24, 2009 IP
  8. wmtips

    wmtips Well-Known Member

    Messages:
    601
    Likes Received:
    70
    Best Answers:
    1
    Trophy Points:
    150
    #8
    No exit() at the end is needed. However, placing exit() at the beginning of your scripts can significantly increase their performance :D
     
    wmtips, Feb 24, 2009 IP
  9. atlantaazfinest

    atlantaazfinest Peon

    Messages:
    389
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #9
    LOL, i tried it and my script didn't seem to run any faster and at times it just comes up blank ... wierd any help on that wmtips?...




    J.k
     
    atlantaazfinest, Feb 24, 2009 IP
  10. wmtips

    wmtips Well-Known Member

    Messages:
    601
    Likes Received:
    70
    Best Answers:
    1
    Trophy Points:
    150
    #10
    LOL, you need a profiler. It must be faster! :D
     
    wmtips, Feb 24, 2009 IP
  11. pfek

    pfek Member

    Messages:
    98
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    45
    #11
    As projectshifter said, there really ain't no need of putting an exit() call at the end of your script, php will automatically exit your script if there ain't no problem in it (like infinite loop).
     
    pfek, Feb 24, 2009 IP
  12. hovesh07

    hovesh07 Well-Known Member

    Messages:
    389
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    108
    #12
    Thanks for all your help. I was using Bluehost and I once I activated their fastCGI option, the hanging stopped.
     
    hovesh07, Feb 25, 2009 IP