views:

29

answers:

2

I was asked to help troubleshoot someone's website. It is written in php, on a linux box, using an apache server and mysql, and I have never worked with any of these before (except maybe linux in school).

I got most of the issues fixed (most code is really the same no matter what langues it is) however there is still one page that is timing out when processing huge files. I'm fairly sure the problem is a timeout somewhere but I have no idea where all the php timeouts would be.

I have adjusted max_execution_time, max_input_time, mysql.connect_timeout, default_socket_timeout, and realpath_cache_ttl in php.ini but it is still timing out after about 10 minutes. What other settings might exist that I could increase to try and fix this?

As a sidenote, I'm aware that 10min is generally not desired when processing an file, however this section of the site is only used by one person once or twice a week and she doesn't mind providing the process finishes as expected !and I really don't want to go rewrite someone else's bad coding in a language I don't understand, for a process I don't understand)

EDIT: The sql process finishes in the background, its just the webpage itself that times out.

A: 

You can use set_time_limit() if you set it to zero the script should not time out at all.

This would be placed within your script, not in any config etc...

Edit: Try changing apache's timeout settings. In the config look for TimeOut directive (should be the same for apache 2.x and apache 1.3.x), once changed restart apache and check it.

Edit 3: Did you go to the link I provided? It lists there the default, which is 300 seconds (5 minutes). Also if the setting IS NOT in the config file, you CAN add it.

According to the docs:

The TimeOut directive currently defines the amount of time Apache will wait for three things:

  1. The total amount of time it takes to receive a GET request.
  2. The amount of time between receipt of TCP packets on a POST or PUT request.
  3. The amount of time between ACKs on transmissions of TCP packets in responses.

So it is possible it doesn't relate, but try it and see.

Viper_Sb
There is an existing line of code in each loop of the process of `set_time_limit(10000);` so I don't think that's the problem. The script appears to go line-by-line through a .csv file and process it. Every item appears in the database despite the page timing out, so I'm beginning to think its an apache timeout instead of a php timeout.
Rachel
There's a decent chance it's a browser timeout. Browsers don't like idling without receiving input. You can sort of work around that by forcing periodic output (e.g. calling `flush()`), but it's a kludge.
Frank Farmer
set_time_limit(10000) within a loop? kinda strange location for it, only needs to be set once per script. Also I doubt it's a browser issuse, as I've updated my answer try apache's TimeOut directive
Viper_Sb
Thanks Frank, I think that's my problem. If you post it as an Answer I'll accept it :)
Rachel
Did you try it? I've had browsers sit for hours while processing, without outputting anything. Up to you if it works it works.
Viper_Sb
Honestly, I can't find the apache Timeout value anywhere. I read somewhere that the default was 30min though, and I'm fairly sure whoever set this up would not have set it lower.
Rachel
I edited instead of putting it in the comment
Viper_Sb
A: 

Per Frank Farmer's suggestion, I added flush() to the code and it works now. Definitely a browser timeout, thanks Frank!

Rachel