Getting a PHP error when I want a CodeIgniter error - php

I'm getting the following PHP error when attempting to upload a file that is too large:
POST Content-Length of 1034425027 bytes exceeds the limit of 33554432 bytes in Unknown
But I have the following set in my controller:
$config['max_size'] = '10000';
All the solutions I see involve increasing post_max_size etc… but I don't want to allow larger files to be uploaded - I want an error, just the CI one, not a PHP one I can do nothing with.
Any ideas? Is this just a flaw in PHP? I'd rather not process the 'false' return in the ajax as a file upload error, because technically that could be produced from any server error.
EDIT; To clarify, as I'm getting requests for code that won't shed any light on anything (I can only assume the question is being misunderstood):
If the file is between 10mb (the limit set by CI) and 32mb (the limit set by post_max_size) everything works fine - there is no code issue. But if the file is large than 32mb PHP catches the file before CI can parse it and provide me with proper errors, so I have no chance to properly flag large files unless I make post_max_size infinitely large - which seems both dangerous and flawed. I'm wondering if there's a way around this. Ideally I don't need the server to get involved until after the CI validation, as I'd rather flag a user friendly error than the POST to just die.

Best bet would be to check the filesize with js [1] before attempting the upload. Short of this, the only options are to increase post size or create your own error hander [2].
[1] https://stackoverflow.com/a/7497439/183254
[2] http://www.php.net/manual/en/function.set-error-handler.php / https://stackoverflow.com/a/11745361/183254

First increase the size in php.ini i.e. upload_max_size. By default PHP settings will be read by php code and then codeigniter settings. So increase the size from .ini file.

Related

PHP file uploading doesn't work over 65KB

I have a VB.NET software that uploads files using an HTTP request to PHP. This worked fine until May but now it fails when uploading files over 65KB. I can not tell when it stops to work exactly. Even though, I don't think it is relevant. So to be clear, uploading a file under 65KB works correctly.
I looked with my hoster and he doesn't see any error neither do I on the server (the part I have access). VB.NET doesn't give me a pertinent error, but using WireShark, I've been able to get either a 500 or a 400 error. But it didn't give me clues on what is failing.
I verified this question which is not solved, though the things said there are OK on the server too.
PHP not uploading file over 55 kb
I have another option to fix it: splitting my files in chunks of 50KB and rejoining them via PHP. Though, I rather understand what is happening because this can happen again even with chunks of 50KB.
Server is Apache/2.4.28 (Unix)
EDIT 1
I have new conditions: I now have my own server running on Windows + Apache 2.4 + PHP 5.6.
Now it goes a little farther. I have an error when using move_uploaded_file function that gives me: Error #3: The uploaded file was only partially uploaded. It is coherent with the file being stopped to be sent near the end. So I now receive an HTTP 200 response but a failure after ward even though I suspect not being there.
I can certify I did not stop my VB.NET software that is uploading the file.
I tested changing KeepAlive to Off/False on both sides. No luck :(
Tried to add header ("Connection: close"); in my main file (that is used for all transactions with this VB.NET software). No luck.
Even though, it is not currently an issue, I changed (PHP configs) the upload_max_filesize to 256M and post_max_size to 300M (because it will be a problem if a can figure out this one).
I got those suggestions from : https://wordpress.stackexchange.com/questions/176465/failed-media-upload-the-uploaded-file-was-only-partially-uploaded
The only one I could not try is replacing an apache/php module which doesn't seem to exist on Windows.
Depending on your server's configuration, when an error 500 is returned an error_log is written. The problem is with the error 400. Which according to wikipedia's list of HTTP codes is actually a BAD REQUEST. Some output from your error_log when the attempt is being made might put us in the right direction.

Error 500 when trying to import large file .txt to MysQL

We're using Yii framework for an internal tool.
What we have now :
The user select a file .txt to upload on the server.
The server clean the text file because it containts lots of characters such as """ and ;;;;
But when comes the time to import to database, server sends a 500 internal error with no more information.
The file size is 8.1 mo. The import seems to work if we delete manually some rows in order to make the file at less than 7 mo.
We took a look at the php.ini file and increased all the limits.
What is weird is that we made local server with easyphp (same config in php.ini) and it works.
Do you have an idea ??
Thanks !
With the information's you have provided, I can only suggest that turn on error_reporting and display_errors in your php.ini file.
Increase maximum execution time and then see if any error displays or not?
Also do you have access to your log files in server? Then check php error_log for more information.
Do you have some error logging (preferably written on the server, as the 500 pages generally not show the error).
Many servers are configured to return a 500 internal error in case of an error in a mysql_query. So either there is omewhere in the 8MB in issue (which does not appear to be the case, if it works in exactly the same table on another server), or the query is too long (increasing the limits is not always possible on a shared server).
If you share some code and/or error message that may help to find the issue.
There is also a limit on the SQL server, defined by max_allowed_packet. Please take a look on the result of
show variables like 'max_allowed_packet';
Maybe this is set to low.

Joomla - Allowed memory size of 1073741824 bytes exhausted

My joomla website started to show following error
Fatal error: Allowed memory size of 1073741824 bytes exhausted (tried to allocate 78 bytes)
I know we can increase the memory limit using ini_set, but I believe it is not the correct way to solve this. Even though, if I set the memory limit to unlimited (-1), I will get an Internal Server Error. I am completely unaware about the recent activities on this site, as I am newly assigned to this task. I tried to disable some plugins and modules using DB. What I did is, just fetch the entries from _modules and _plugins with descending order of id and change the publish to 0. But nothing works. I am getting the same error (Fatal error: Allowed memory...). I tried to open the admin page, that is also not loading. Just showing a blank page.
Please help me to fix this. I am new to joomla
I don't believe you're going to receive a concise answer for this type of problem as it is far too broad. It sounds like you have a memory leak. See:
How to find which PHP script is leaking memory?
Diagnosing Memory Leaks - Allowed memory size of # bytes exhausted
Unfortunately, finding the cause of a memory leak is seldom a simple task. The two links above do provide some useful tips, namely placing calls to memory_get_usage and also the Xdebug extension.
Even if you weren't new to Joomla and more familiar with the code base, it probably wouldn't make solving this problem any easier.
Lets start with what that message is telling you.
PHP is saying I have successfully allocated a GIGABYTE of memory for this code to run with but I now need to allocate another 78 bytes but I cannot because I have reached my limit.
The part of that statement that should be shouting at you is Its already allocated a GIGABYTE of memory for this processing. That is just ridiculous.
Either as was suggested by #mistermartin some code is causing a memory leak or you have some code in the process that failed that is consuming ridiculously large amounts of memory
That message usually is associated with a stack trace telling you in which piece of code this error happened, and which piece of code called that, etc, etc.
Question: Does it always happen in the same piece of code? If so thats where you start looking.
I would start by looking through all the code in that stack trace, not just the particular script that actually broke the camels back so to speak. Work your way back through all the code that has been executed looking for something that has the potential to allocate hugh amounts of memory, arrays are a good place to start but they are not the only possibility.
I would personally copy the site ( complete with database ) to a test environment where you can either use a decent debugger to follow the code through an execution of the offending code.
If you cannot setup a debugger then at least in a test environment you can add some debugging code to tell you where and when memory starts to be consumed at this riduculous rate.
If you are looking for a way to fix this issue please follow the below methods. But it's not adviced to use it since it does not solve the issue you have with your program(code). You still should check why the memory is exhausted.
1 Using PHP Code
ini_set('memory_limit', '-1'); // This will take unlimited memory usage of server
Above method is not working for you as you say.
2 Using php.ini
Change the line in php.ini If your line shows 32M try 128M.
memory_limit = 128M ;
Maximum amount of memory a script may consume (128MB)
How to debug the code
Your program is consuming memory than it need. This can often happen in PHP if you have a loop that has run out of control and you are creating objects or adding to arrays on each pass of the loop. Check for infinite loops.
How to find which PHP script is leaking memory?
I am not too familiar with Joomla, but verified it redirects traffic through an index.php file similar to many other frameworks and apps. A decent first step to finding WHERE the leak is would be adding the following to the index.php file.:
function shutdown() {
$aError = error_get_last();
if ($aError["type"] == E_ERROR ) {
openlog("Fatal Error Shutdown Log: ", LOG_ODELAY, LOG_USER);
syslog(LOG_ERR, 'Message: ' . $aError['message'] . PHP_EOL);
syslog(LOG_ERR, "File: " . $aError['file'] . PHP_EOL );
syslog(LOG_ERR, "Line: " . $aError['line'] . PHP_EOL );
}
}
register_shutdown_function( 'shutdown' );
Check your syslog for the string "Fatal Error Shutdown Log:" and it should give you the specific location the memory leak is occurring. If Joomla has a more appropriate location to put this code, go for it. In theory shutdown functions will run no matter what. all this does is log only the fatal errors to your syslog. Memory errors are fatal errors. Good luck.
I have experienced a similar issue with ridiculously long SQL strings (inherited code was imploding a massive array into an IN condition). Log your SQL queries and check they dont exceed the max_allowed_packet (1GB)
http://dev.mysql.com/doc/refman/5.1/en/packet-too-large.html
You could start by enabling Joomla debugging. On Joomla 3 it's at the backend > global configuration > system > debug system
Then, on the front end of your site your template should give some debugging info.
I would start by looking for clues in the Profile Information and Memory Usage sections
Good luck!
Edit
Admittedly this is bit of a long shot, but maybe there are some Akeeba backups siting on the site that you could use. Look for some Akeeba .jpa files, probably in site_root/administrator/components/com_akeeba/backup/
If there are, I would start by restoring them to another machine so that you can rule out any server php related errors as well.
Maybe you'll be lucky.
I had this problem also - for my /administrator/ folder. None of the configuration or php.ini memory limit changes fixed the problem, which I tracked down to being connected to the fact that I'd changed the name of my /administrator/ folder in order to make it more difficult for hackers. Shouldn't have made a difference, if code was using relative paths, but apparently some code did not. Now, I rename the folder back to default to use admin features, then back to a random name to give the hackers a better challenge. So, have you changed any folder names??? I hope this helps someone.

PHP: Check for dropped/cropped POST-data

PHP has several limits on POST-data (overall data size limit as well as field-limits). I currently get no warnings when I run into these limits - except missing data.
Is there a way to check whether PHP ran into one of these limits?
You need to change your error reporting level so that it displays warnings, as a warning is outputted when the POST size is reached.
error_reporting(E_ALL);
Setting error_reporting to E_ALL includes E_WARNING, however you could just use E_WARNING if you didn't want other errors to be reported.
If you wanted the errors to be outputted, ensure you have display_errors set to on or 1. If you don't, you can do so locally by using display_errors(1);
Regardless of whether you displays errors or not, they will still be logged to your PHP error log file.
You can check or change value in php.ini or .htaccess:
post_max_size
There are also another limits in this file:
max_input_nesting_level
memory_limit
upload_max_filesize
max_input_time
max_input_vars
You can control these using .htaccess, like so:
php_value post_max_size 100M
Also check if there are errors during processes using:
error_reporting(E_ALL);
Your application can check these settings. Use ini_get() for this.
For example:
ini_get('post_max_size'); // in bytes
Be aware that this is a development and deployment issue, because your PHP script (even the whole Apache server) may be reverse proxied, and anyway there can be any number of intermediate agents having a limit on the request and thus truncating it.
Thus the first step is ensuring that the PHP limit for post requests size is the least in the chain of server software that handle the request.
Then, I suggest you read this question (and answers and comments) to get an idea of what you can do and what the platform gives you, and especially how cumbersome and somewhat unreliable it is to detect such an error.
Anyway, I think you should not be too scared about not giving users feedback about the data entered: after all, everything has a limit (think of database columns size, disk space and so on) and adequate sizing is more important than issuing an error message. At least, I can't even remember the last time a service complained about the request size. If you are especially interested in file upload limits, instead, that's quite a different thing because it's easier to know, in the PHP script, if the user hit the given limits.

PHP Configuration - Memory

In my php.ini file I have
memory=40M
What does this do (it solves some problems that I have been having). Note that this is NOT:
memory_limit=128M
I know memory limit sets the maximum amount of memory a PHP script can use, but what does memory do?
EDIT
I recognize this is not a standard directive, but it is fixing my problem. Without it my pages randomly produce 500 errors, but then I put this line in and they go away.
This is where I got the fix from:
http://www.archtopia.com/2010/01/30/wordpress-internal-server-error-500-with-1and1-webhosting/
memory is not a valid php.ini directive. It may be solving your problem because it is not recognized, in turn resorting to a default value that does in fact work. Also note that "megabyte" should be M not MB.
The proper way to set the value is:
memory_limit=40m
I can't find the memory directive on http://php.net/manual/en/ini.core.php. Are you sure it's correct and not a typo?

Categories