Jump to content

Recommended Posts

I am calling an php file that reads 7000~ rows of MySQL data and saves almost all (depending on filters) data into an array and then into an Excel file ready for download, all via an ajax call from another php page.

 

It seems to work when I put a LIMIT up to around 1000~ (doesn't always work on 1000, maybe due to server load from other websites?), otherwise it returns a javascript popup (from the ajax) with a 500 internal server error, then seems to take my website offline for that reason for 10 minutes or so.

 

I have used the code;

 

ini_set('max_execution_time', '300');
ini_set("max_input_time","120");
ini_set("memory_limit","100M");

 

on both the main php page and the one I am calling via ajax with no joy.

 

Based on the overall functionality is there anything I can do to stop this Internal server error triggering? (I know the functionality works OK, because if I limit the db call to 700 rows or less it works fine).

 

Many thanks.

Link to comment
https://forums.phpfreaks.com/topic/154330-solved-500-internal-server-error/
Share on other sites

A few thoughts / ideas:

 

First, have you verified that the ini_set's are taking effect (check with phpinfo();)

Second, are you selecting JUST the data that you need? (i.e. "SELECT id, name" rather than "SELECT *")

Thirdly, is there a way that you can batch the selects and do say 500 at a time.

Fourtly, (and probably the most important) can you apply your filters using the SQL query so that you only select the rows that you need?

Lastly, can you streamline the process as much as possible? Do you need to go via an array or can you just grab a row from the db and put it straight where it needs to go rather than into the array then to where it needs to go?

Hi Soak thanks for your reply.

 

1) I will test phpinfo once my website comes back up from the last failed test :P

2) I am just selecting the rows I need yes.

3) The batch selects is a solution I'm sure will work, but I was avoiding it because of extra development time in case it was resolvable with current function. Looks like I might have to go down that route.

4) Yes but unfortunately for this particular requirement the filter means it is almost every row that is returned.

5) I thought putting all the data in an array and then writing to a file at the end might be faster then writing to a file on every step of the loop a thousand times?

2) Not just the rows, only the fields that you need.

5) It probably would. I suspect that a straightforward string would use less memory than an array though (I don't know this for fact but I'd be very surprised if it wasn't true). You could also write the string to the file every 500 or so lines and be back down to 0kb memory usage ;-)

 

2) Sorry miss-typed there, I meant fields.

 

Oddly enough, when I try to load another php page that doesn't have much in it, say just an echo statement, it loads OK, but when I try to load other parts of the site that I know work, and my problem script it comes up with Internal Server error for a good 10 minutes before allowing me back in. Does anyone know much about this 500 error code and what might cause it lock up other php files, does it crash sessions?databases?file reading? and therefore prevent any other file that uses these functions to load until it resolves itself?

http://pcsupport.about.com/od/findbyerrormessage/a/500servererror.htm

 

Where I work, these are typically caused by a server running out of memory or some other fatal error.  My guess is you are passing too much information in an array or via non-standard methods.  That is a lot of data to send back and forth via HTTP requests.

 

I would consider another method of generating the Excel file.

  • 1 month later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.