Web Analytics Made Easy -
StatCounter Connection Reset with Server - CodingForum

Announcement

Collapse
No announcement yet.

Connection Reset with Server

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Connection Reset with Server

    All,
    I've made changes to my php.ini file so that none of my scripts time out but I believe have an issue that the server that I'm trying to get information from resets my connection. Is there a way to dynamically switch my IP address or something like that to avoid their server resetting my connection? I'm trying to use get_file_contents as I'm crawling through the website. Thanks in advance.
    Last edited by treeleaf20; Aug 24, 2011, 04:49 PM. Reason: Gave more information

  • #2
    This isn't going to be a problem with PHP.
    What are you going to switch your IP to? If you're talking of your client and you have multiple static addresses, then sure. If its on DHCP, then you can ask for a new one, though typically you get the same one back. If you are referring to your server, then you sure don't want to do that.
    Have you tried connecting to your site by address instead of by dns?
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

    Comment


    • #3
      So for example, if I wanted to get some information from like yellowpages.com and I was doing multiple file_get_contents and then all of a sudden after a couple minutes (maybe 1 or 2) my connection got reset what would cause this? I'm just doing this through my localhost on my computer so I know that my settings for my php files are ok. When you say connect to the site without dns, are you saying to put in the ip address of yellowpages?

      Comment


      • #4
        I can't see it throwing a connection reset. I can see it throwing a timeout or cyclic.
        Do you get the same behaviour when you use sockets or curl?
        PHP Code:
        header('HTTP/1.1 420 Enhance Your Calm'); 
        Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

        Comment


        • #5
          I don't know how to use sockets but haven't tried to use curl yet either. I got a message from localhost that says:

          The connection to localhost was interrupted.

          My script doesn't output anything, it just does a whole bunch of crawling through webpages and inserts some data into my database. It probably ran for 5 minutes before it gave me this message. I'm also running XAMPP if that makes a difference.

          Comment


          • #6
            Have you tried to set ignore_user_abort and disable the time limit of the script?
            XAMPP shoudn't make a difference.
            PHP Code:
            header('HTTP/1.1 420 Enhance Your Calm'); 
            Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

            Comment


            • #7
              Here is the PHP file:
              ;;;;;;;;;;;;;;;;;;;
              ; Resource Limits ;
              ;;;;;;;;;;;;;;;;;;;

              ; Maximum execution time of each script, in seconds
              ; http://php.net/max-execution-time
              ; Note: This directive is hardcoded to 0 for the CLI SAPI
              max_execution_time = 0

              ; Maximum amount of time each script may spend parsing request data. It's a good
              ; idea to limit this time on productions servers in order to eliminate unexpectedly
              ; long running scripts.
              ; Note: This directive is hardcoded to -1 for the CLI SAPI
              ; Default Value: -1 (Unlimited)
              ; Development Value: 60 (60 seconds)
              ; Production Value: 60 (60 seconds)
              ; http://php.net/max-input-time
              max_input_time = -1

              ; Maximum input variable nesting level
              ; http://php.net/max-input-nesting-level
              ;max_input_nesting_level = 64

              ; Maximum amount of memory a script may consume (128MB)
              ; http://php.net/memory-limit
              memory_limit = 128M

              Also I just removed the semicolon in front of the ignore_user_abort so that should be ok now. Does everything look ok now?

              Comment


              • #8
                I also noticed this in the documentation:

                Your web server can have other timeout configurations that may also interrupt PHP execution. Apache has a Timeout directive and IIS has a CGI timeout function. Both default to 300 seconds. See your web server documentation for specific details.

                Do I have to do something with the Apache configuration to make it higher then 300 or will the ignore_user_abort not make that relevant?

                Comment


                • #9
                  Originally posted by treeleaf20 View Post
                  I also noticed this in the documentation:

                  Your web server can have other timeout configurations that may also interrupt PHP execution. Apache has a Timeout directive and IIS has a CGI timeout function. Both default to 300 seconds. See your web server documentation for specific details.

                  Do I have to do something with the Apache configuration to make it higher then 300 or will the ignore_user_abort not make that relevant?
                  You'll need to configure the Apache. Modify the httpd.conf and alter the timeout to 0.

                  Edit:
                  Also, you said this is on a localmachine? Why not just execute via CLI instead of through apache?
                  PHP Code:
                  header('HTTP/1.1 420 Enhance Your Calm'); 
                  Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

                  Comment


                  • #10
                    I tried to set this to be 0 on the apache timeout but then the localhost wouldn't work so I set it to just a large number.

                    It is on a local machine but not sure how to do it with a CLI? Can you tell me how to do that?

                    Comment


                    • #11
                      >php -f "/path/to/phpfile.php"
                      It will run in the command window instead which has no timeout.
                      PHP Code:
                      header('HTTP/1.1 420 Enhance Your Calm'); 
                      Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

                      Comment


                      • #12
                        I opened up the CMD window and typed in the following:

                        php -f "D:/My Documents/xampp/htdocs/folder/file.php"

                        It gave me the message: 'php' is not recognized as an internal or external command operable program or batch file

                        Comment


                        • #13
                          You're path isn't registered with PHP. You'll need to specify it:
                          Code:
                          >/path/to/php.exe -f "D:/My Documents/xampp/htdocs/folder/file.php"
                          PHP Code:
                          header('HTTP/1.1 420 Enhance Your Calm'); 
                          Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

                          Comment


                          • #14
                            Ok, I got that to work now I've got a lot of error messages:

                            PHP Deprecated: Assigning the return value of new by reference is deprecated in D:\My Documents\xampp\php\PEAR\config.php on line 166

                            PHP Deprecated: Assigning the return value of new by reference is deprecated in D:\My Documents\xampp\php\PEAR\Config\Container.php on line 111

                            Then some messages that it couldn't connect to my database becuase I'm using localhost.

                            Comment


                            • #15
                              The first errors are backwards compatibility issues: $obj = &new classObject();. Nothing to worry about at this point.
                              Change you're database configuration to use 127.0.0.1:3306 for its host.
                              PHP Code:
                              header('HTTP/1.1 420 Enhance Your Calm'); 
                              Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

                              Comment

                              Working...
                              X
                              😀
                              🥰
                              🤢
                              😎
                              😡
                              👍
                              👎