Long running PHP script problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rpnew
    New Member
    • Aug 2007
    • 189

    Long running PHP script problem

    Hi,
    I've one PHP script which runs for long time(as it suppose to). Basically it searches on Google and Yahoo and then i'm doing some processing. It runs perfectly sometimes and sometimes it dosent.

    Like in Firefox when it dosent run it gives me download dialog box to download the same script i'm running and in Konqueror it shows connection broken to localhost instead.

    I'm sure that there is nothing wrong with the script as it shows correct output sometimes.. but there something to do with the time its taking..
    so what can i do to avoid this...
    I've also used sleep().... or... flush() but still not much luck..

    Regards,
    RP
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    Originally posted by rpnew
    Hi,
    I've one PHP script which runs for long time(as it suppose to). Basically it searches on Google and Yahoo and then i'm doing some processing. It runs perfectly sometimes and sometimes it dosent.

    Like in Firefox when it dosent run it gives me download dialog box to download the same script i'm running and in Konqueror it shows connection broken to localhost instead.

    I'm sure that there is nothing wrong with the script as it shows correct output sometimes.. but there something to do with the time its taking..
    so what can i do to avoid this...
    I've also used sleep().... or... flush() but still not much luck..

    Regards,
    RP
    Not quite understanding the problem but have you tried set_time_limit( )?

    Comment

    • rpnew
      New Member
      • Aug 2007
      • 189

      #3
      Originally posted by markusn00b
      Not quite understanding the problem but have you tried set_time_limit( )?
      well yeah i've that line in my PHP script. and my script runs for more than an hour sometimes but when it dosent it shows error "connection to host is broken".... Like a while ago my internet was down for 5-10 min. so i was getting same error for this site(bytes.com) ...

      Regards,
      RP

      Comment

      • Markus
        Recognized Expert Expert
        • Jun 2007
        • 6092

        #4
        Originally posted by rpnew
        well yeah i've that line in my PHP script. and my script runs for more than an hour sometimes but when it dosent it shows error "connection to host is broken".... Like a while ago my internet was down for 5-10 min. so i was getting same error for this site(bytes.com) ...

        Regards,
        RP
        OVER AN HOUR?!

        What the !#*$

        Maybe you're just killing your internet?

        Comment

        • rpnew
          New Member
          • Aug 2007
          • 189

          #5
          Originally posted by markusn00b
          OVER AN HOUR?!
          Maybe you're just killing your internet?


          ahh.. well net is working fine all the time.. and even my script runs well once in a while... and i dont think i'm killing internet as my script uses internet with proper sleep()... it uses internet with some gaps.... if i dont use sleep() then my script should be finish not more then in 20 minutes its only sleep() that making it run that long.. however without sleep as well i'm geting same problem.... so anything i can do to solve that???

          Originally posted by markusn00b
          What the !#*$
          search on Google and you'll find people with scipts running over 2-3 hours.....

          Regards,
          RP

          Comment

          • TheServant
            Recognized Expert Top Contributor
            • Feb 2008
            • 1168

            #6
            Originally posted by rpnew
            ahh.. well net is working fine all the time.. and even my script runs well once in a while... and i dont think i'm killing internet as my script uses internet with proper sleep()... it uses internet with some gaps.... if i dont use sleep() then my script should be finish not more then in 20 minutes its only sleep() that making it run that long.. however without sleep as well i'm geting same problem.... so anything i can do to solve that???



            search on Google and you'll find people with scipts running over 2-3 hours.....

            Regards,
            RP
            You say it searches google? What do you mean by that. And there has to be a more efficient way of doing it because even 20mins is too long for any script!

            Comment

            • rpnew
              New Member
              • Aug 2007
              • 189

              #7
              Originally posted by TheServant
              You say it searches google? What do you mean by that. And there has to be a more efficient way of doing it because even 20mins is too long for any script!
              By that what i meant was.. i post some keyword to Google and Yahoo and then get the result and then i need to do some processing on result which i store in the database... one of the feature of my script is to count the pagerank.. and some other stuff....

              Now my problem is sometimes it works up to the end(however once in a while)... but most of the time it hangs in between giving error "connection to localhost broken".. i cant figure out what this error is..... and how to solve it..


              Regards,
              RP

              Comment

              • TheServant
                Recognized Expert Top Contributor
                • Feb 2008
                • 1168

                #8
                Originally posted by rpnew
                By that what i meant was.. i post some keyword to Google and Yahoo and then get the result and then i need to do some processing on result which i store in the database... one of the feature of my script is to count the pagerank.. and some other stuff....

                Now my problem is sometimes it works up to the end(however once in a while)... but most of the time it hangs in between giving error "connection to localhost broken".. i cant figure out what this error is..... and how to solve it..


                Regards,
                RP
                In that case we will need to see some of your code. Where you think it's going wrong, post that. Also the exact error msg. We cannot guess where you have gone wrong - Well we could, but we are not paid, so we will not waste our time.

                Comment

                • rpnew
                  New Member
                  • Aug 2007
                  • 189

                  #9
                  Originally posted by TheServant
                  In that case we will need to see some of your code. Where you think it's going wrong, post that. Also the exact error msg. We cannot guess where you have gone wrong - Well we could, but we are not paid, so we will not waste our time.
                  Well cant give you the exact code(dont get me wrong here) as my script hangs at different level... as i'm using flush to know what is happening.. i can see it shows output and gives error at different level..... I've searched on google and not found much but one thing that it has something to do with server overloading or somethig.. so serching for something to optimise my code... well just half an hour ago that script almost ran for an hour and then gave me that error... "connection to localhost broken".....
                  will get back with result soon.........

                  Regards,
                  RP

                  Comment

                  • TheServant
                    Recognized Expert Top Contributor
                    • Feb 2008
                    • 1168

                    #10
                    Originally posted by rpnew
                    Well cant give you the exact code(dont get me wrong here) as my script hangs at different level... as i'm using flush to know what is happening.. i can see it shows output and gives error at different level..... I've searched on google and not found much but one thing that it has something to do with server overloading or somethig.. so serching for something to optimise my code... well just half an hour ago that script almost ran for an hour and then gave me that error... "connection to localhost broken".....
                    will get back with result soon.........

                    Regards,
                    RP
                    I understand if you don't want to show your code, but we can;t help you without it. Let us know if you have a more specific question about a sample of your code (you need to provide this too) and we will help as we can. Good luck.

                    Comment

                    • dlite922
                      Recognized Expert Top Contributor
                      • Dec 2007
                      • 1586

                      #11
                      Originally posted by rpnew
                      Well cant give you the exact code(dont get me wrong here) as my script hangs at different level... as i'm using flush to know what is happening.. i can see it shows output and gives error at different level..... I've searched on google and not found much but one thing that it has something to do with server overloading or somethig.. so serching for something to optimise my code... well just half an hour ago that script almost ran for an hour and then gave me that error... "connection to localhost broken".....
                      will get back with result soon.........

                      Regards,


                      RP

                      I know what you're trying to do here. Some members gawk at hour long script, but that's what you're using it for.

                      The thing that raises red flags is "connection to localhost broken", more precisely the word localhost.

                      This, I assume, is because your running this in a browser ON the server.

                      Second, the issue might not be related to your script at all, but the browser. They don't like pages taking an hour to load.

                      Why don't you run the script from the command line :-)

                      if in linux:

                      php -q -f /path/to/your/script.php

                      In windows......er m...is something similar :D

                      You can even add your script to crontab or schedule task so it can do the work even while you sleep!

                      Let me know if you get this same timeout while running script in command line.

                      Good luck,


                      Dan

                      Comment

                      • rpnew
                        New Member
                        • Aug 2007
                        • 189

                        #12
                        Originally posted by dlite922
                        I know what you're trying to do here. Some members gawk at hour long script, but that's what you're using it for.

                        The thing that raises red flags is "connection to localhost broken", more precisely the word localhost.

                        This, I assume, is because your running this in a browser ON the server.

                        Second, the issue might not be related to your script at all, but the browser. They don't like pages taking an hour to load.

                        Why don't you run the script from the command line :-)

                        if in linux:

                        php -q -f /path/to/your/script.php

                        In windows......er m...is something similar :D

                        You can even add your script to crontab or schedule task so it can do the work even while you sleep!

                        Let me know if you get this same timeout while running script in command line.

                        Good luck,


                        Dan
                        Hi,
                        First of all.. thanks... how could i not think of that earlier... anyways... i tried it from command line and on first go it finished upto end.. i think for the first time .. anyways... i think its working from command line... i'm on linux so may be i would call it through shell script + curl ... and even may be put it in cron.......etc etc .....

                        Anyways.. thanks to all ...

                        Regards,
                        RP

                        P.S. - Script went for 1hr 35min almost.... :)

                        Comment

                        Working...