...

View Full Version : Connection Reset with Server



treeleaf20
08-24-2011, 09:25 PM
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.

Fou-Lu
08-24-2011, 10:46 PM
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?

treeleaf20
08-24-2011, 10:54 PM
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?

Fou-Lu
08-24-2011, 10:56 PM
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?

treeleaf20
08-24-2011, 11:03 PM
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.

Fou-Lu
08-24-2011, 11:07 PM
Have you tried to set ignore_user_abort and disable the time limit of the script?
XAMPP shoudn't make a difference.

treeleaf20
08-24-2011, 11:11 PM
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?

treeleaf20
08-24-2011, 11:18 PM
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?

Fou-Lu
08-24-2011, 11:34 PM
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.


Also, you said this is on a localmachine? Why not just execute via CLI instead of through apache?

treeleaf20
08-25-2011, 02:55 PM
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?

Fou-Lu
08-25-2011, 03:06 PM
>php -f "/path/to/phpfile.php"
It will run in the command window instead which has no timeout.

treeleaf20
08-25-2011, 03:11 PM
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

Fou-Lu
08-25-2011, 03:12 PM
You're path isn't registered with PHP. You'll need to specify it:


>/path/to/php.exe -f "D:/My Documents/xampp/htdocs/folder/file.php"

treeleaf20
08-25-2011, 03:17 PM
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.

Fou-Lu
08-25-2011, 03:24 PM
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.

treeleaf20
08-25-2011, 03:27 PM
Ok, did that. Right now my database username is root. It's saying access denied for user ''@'localhost using password NO.

Do I need to create a user for my database?

Fou-Lu
08-25-2011, 03:29 PM
No root is fine. But its quite rare to see root without a password in use; it is possible that your root is not configured for localhost connections, but that wouldn't work in apache either in that case.

Wait a sec, that error shows you have no user in use.

treeleaf20
08-25-2011, 03:37 PM
I had my config.php file as an include on my script it was trying to run. I updated the config.php file but it wouldn't work. I just put the content of the config.php file in the script I'm trying to execute and now it's running fine. Not sure what that is the case though.

Fou-Lu
08-25-2011, 03:56 PM
Sounds to me like something isn't set right. The username is empty in the above error, so without seeing the code you have it makes it tough to say where the issue lies.

treeleaf20
08-25-2011, 04:47 PM
Ok, it all works fine. However, my IP address got banned on their site. Is there a way to hide this or mask it so it looks like the requests are coming from different IP addresses?

Fou-Lu
08-25-2011, 04:49 PM
Ok, it all works fine. However, my IP address got banned on their site. Is there a way to hide this or mask it so it looks like the requests are coming from different IP addresses?

We will not be discussing the changing of IP addresses. Clearly you have violated their TOS and have removed your ability to crawl.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum