I have developed a PHP web app. I am giving an option to the user to update multiple issues on one go. In doing so, sometimes the user is encountering this error. Is there any way to increase the lenght of URL in apache?
Under Apache, the limit is a configurable value, LimitRequestLine
. Change this value to something larger than its default of 8190 if you want to support a longer request URI. The value is in /etc/apache2/apache2.conf. If not, add a new line (LimitRequestLine 10000
) under AccessFileName .htaccess
.
However, note that if you’re actually running into this limit, you are probably abusing GET
to begin with. You should use POST
to transmit this sort of data — especially since you even concede that you’re using it to update values. If you check the link above, you’ll notice that Apache even says “Under normal conditions, the value should not be changed from the default.”
Share Follow
2,65111 gold badge2828 silver badges3939 bronze badges
answered May 23, 2010 at 11:55
I tried using POST at first, but this is an update operation on the database, and I am refreshing the orginal page using the values that were originally posted to that page.
JPro: Updating a database is more or less the exact reason you would use POST
. Nothing about using POST precludes you from populating the same form with the fields that were just posted, so I’m not sure what you mean by that.
@JPro: The usual technique in that case is to POST to the same page. The handler for the page (which can be the same code for both GET and POST) first checks for POST parameters, handles them if it finds them, then returns the page with the proper values filled in, which will be either the updated values (if POST and the update succeeds) or the original values (if GET, or if POST and the update fails). If the update fails, you can even have per-field error messages describing the failure.
I figured this out pretty late, so I would like to share it. If you can’t find the word LimitRequestLine
anywhere in your httpd.conf file, just add the line yourself anywhere you like. For example: LimitRequestLine 100000
“it can not fixed” tells me nothing. Also, I’m not sure Apache will allow 100k request lines; that’s a really over-the-top size. You probably need to rethink your approach, and use something else besides GET if you have that many query parameters.
Based on John’s answer, I changed the GET request to a POST request. It works, without having to change the server configuration. So I went looking how to implement this. The following pages were helpful:
jQuery Ajax POST example with PHP (Note the sanitize posted data remark) and
http://www.openjs.com/articles/ajax_xmlhttp_using_post.php
Basically, the difference is that the GET request has the url and parameters in one string and then sends null:
http.open("GET", url+"?"+params, true);
http.send(null);
whereas the POST request sends the url and the parameters in separate commands:
http.open("POST", url, true);
http.send(params);
Here is a working example:
ajaxPOST.html:
<html>
<head>
<script type="text/javascript">
function ajaxPOSTTest() {
try {
// Opera 8.0+, Firefox, Safari
ajaxPOSTTestRequest = new XMLHttpRequest();
} catch (e) {
// Internet Explorer Browsers
try {
ajaxPOSTTestRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
ajaxPOSTTestRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {
// Something went wrong
alert("Your browser broke!");
return false;
}
}
}
ajaxPOSTTestRequest.onreadystatechange = ajaxCalled_POSTTest;
var url = "ajaxPOST.php";
var params = "lorem=ipsum&name=binny";
ajaxPOSTTestRequest.open("POST", url, true);
ajaxPOSTTestRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
ajaxPOSTTestRequest.send(params);
}
//Create a function that will receive data sent from the server
function ajaxCalled_POSTTest() {
if (ajaxPOSTTestRequest.readyState == 4) {
document.getElementById("output").innerHTML = ajaxPOSTTestRequest.responseText;
}
}
</script>
</head>
<body>
<button onclick="ajaxPOSTTest()">ajax POST Test</button>
<div id="output"></div>
</body>
</html>
ajaxPOST.php:
<?php
$lorem=$_POST['lorem'];
print $lorem.'<br>';
?>
I just sent over 12,000 characters without any problems.
I have a simple workaround.
Suppose your URI has a string stringdata
that is too long. You can simply break it into a number of parts depending on the limits of your server. Then submit the first one, in my case to write a file. Then submit the next ones to append to previously added data.
Can you provide an example? I can see how you split the string when it’s user generated…
4
Very cheap workaround. It is better to reconsider the domain problem!
19
This doesn’t deserve to have so many downvotes. There certainly are situations in which submitting multiple requests can be an acceptable workaround. True, the quality of the answer is a bit low, but that’s to be expected from a user who is brand new to SO. Let’s show some love and offer feedback instead of just downvoting newcomers that don’t “get” SO yet!
– rinogo
1
I agree, it looks viable
I got this error after using $.getJSON() from JQuery. I just changed to post:
data = getDataObjectByForm(form);
var jqxhr = $.post(url, data, function(){}, 'json')
.done(function (response) {
if (response instanceof Object)
var json = response;
else
var json = $.parseJSON(response);
// console.log(response);
// console.log(json);
jsonToDom(json);
if (json.reload != undefined && json.reload)
location.reload();
$("body").delay(1000).css("cursor", "default");
})
.fail(function (jqxhr, textStatus, error) {
var err = textStatus + ", " + error;
console.log("Request Failed: " + err);
alert("Fehler!");
});
is this an answer or question?
– Takarii
This is a good quick fix. Changing from get to post allows the long URL without any server config change.
– mt025
An excerpt from the RFC 2616: Hypertext Transfer Protocol — HTTP/1.1:
The POST method is used to request that the origin server accept the entity enclosed in the request as a new subordinate of the resource identified by the Request-URI in the Request-Line. POST is designed to allow a uniform method to cover the following functions:
- Annotation of existing resources;
- Posting a message to a bulletin board, newsgroup, mailing list, or similar group of articles;
- Providing a block of data, such as the result of submitting a form, to a data-handling process;
- Extending a database through an append operation.
Not seeing how this answers the question..?
– q9f
The original poster said that the records are being updated. For updates, it is good practice to use POST or PUT and not GET. But, of course, it might be that the URL max limit gets exceeded when retrieving the records to display before updating, and then GET method is appropriate, but it can fail because of this limit. The original poster didn’t mention at which stage the problem arises, so it can be assumed that it was during the update itself, but we can’t be sure…
source : https://stackoverflow.com/questions/2891574/how-do-i-resolve-a-http-414-request-uri-too-long-error