How to terminate a script

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • adamalton
    New Member
    • Feb 2007
    • 93

    How to terminate a script

    I've got a script which uses cURL to connect to another website, and it seems to be getting stuck (I can't quite figure out how, but that's besides the point!). The trouble is that when my script runs it redirects you to a "please wait" page, and it then executes by itself. So you can't click 'stop' in your browser to terminate the script. If the script gets a fatal error, then the 'results' page will display an error saying that the script failed. If the script finishes successfully then obviously the 'results' page will have the results on it.

    But my script appears to get stuck, and just never produces a results page, and never produces an error. So it must still be executing. The script wouldn't necessarily time out because time spent doing cURL connections doesn't count towards the script's execution time. And despite my cURL settings, cURL doesn't seem to timeout either. So my script is stuck in eternal limbo, which worries me because I've now probably got several scripts all running forever on my webserver! (Deleting the php file doesn't help, because php appears to store it in ram in order to execute it, so it keeps running even after you've deleted it.)

    So to get to the point.....

    How can I get php to terminate everything its doing (i.e. all scripts that its running) without shutting down the webserver? I can't shut down the web server because it's on a paid hosting thing, and I don't have that kind of access to it (only cpanel).

    What are 'cron jobs'? Could I create one that resets php?
  • mwasif
    Recognized Expert Contributor
    • Jul 2006
    • 802

    #2
    Check out this link to know about cronjob.

    Set timeouts (CURLOPT_CONNEC TTIMEOUT and CURLOPT_TIMEOUT ) for cURL using curl_setopt.

    Comment

    • adamalton
      New Member
      • Feb 2007
      • 93

      #3
      Yeah, I'm already using CURLOPT_TIMEOUT , CURLOPT_CONNECT TIMEOUT , CURLOPT_LOWSPEE DLIMIT, and CURLOPT_LOWSPEE D_TIME. Which is why I can't understand why it's getting stuck.

      I'll have a read about cronjobs

      Comment

      • Motoma
        Recognized Expert Specialist
        • Jan 2007
        • 3236

        #4
        Originally posted by adamalton
        But my script appears to get stuck, and just never produces a results page, and never produces an error. So it must still be executing.
        Not necessarily. Take a look at the top post in this forum, it will tell you how to ensure that you receive all error messages for properly debugging php scripts.

        Comment

        • adamalton
          New Member
          • Feb 2007
          • 93

          #5
          It appears that my scripts are not getting stuck at all! Quite the opposite...they are failing...silen tly!

          The curl_multi_sele ct() function causes php to fail, without outputting any error message. I've submitted a bug on the php.net site.

          Comment

          • Motoma
            Recognized Expert Specialist
            • Jan 2007
            • 3236

            #6
            Originally posted by adamalton
            It appears that my scripts are not getting stuck at all! Quite the opposite...they are failing...silen tly!

            The curl_multi_sele ct() function causes php to fail, without outputting any error message. I've submitted a bug on the php.net site.
            Hrm, could you post a simple test case for us to try out?

            Comment

            • adamalton
              New Member
              • Feb 2007
              • 93

              #7
              I'll have more of an investiagtion today, and see if I can post some example code.

              The problem is that I'm using the function in a script which is included in another script which is included in another script, and sometimes when the script is included it works and sometimes when it's included it just fails, silently. I can't figure out what makes it fail, but it definitely shouldn't just fail silently.

              Here's my bug:
              http://bugs.php.net/bug.php?id=4202 0

              Comment

              • tscott
                New Member
                • Jul 2007
                • 22

                #8
                Hmm... Code looks really disorganized to me and there aren't as many {} as there should be, a while statement was ended with a ; . Yeah... that code = :S

                Needs to be dubugged.

                ~Tyler

                Comment

                • adamalton
                  New Member
                  • Feb 2007
                  • 93

                  #9
                  Trust me, the code works. And anyway, if it didn't then php would give an error message, not just self destruct! The strange thing is that the problem never occurs on my own server (Mac OSX) but it does on my webhost's, despite them both having the same php version. I'm going to start a new discussion to get some help with disabling the optimizers etc to see if they are causing the problem.

                  Comment

                  • Motoma
                    Recognized Expert Specialist
                    • Jan 2007
                    • 3236

                    #10
                    Originally posted by adamalton
                    Trust me, the code works. And anyway, if it didn't then php would give an error message, not just self destruct! The strange thing is that the problem never occurs on my own server (Mac OSX) but it does on my webhost's, despite them both having the same php version. I'm going to start a new discussion to get some help with disabling the optimizers etc to see if they are causing the problem.
                    Any hopes of us getting a simple test case to demonstrate the bug?

                    Comment

                    Working...