之前在寫Picasa2Wordpress的時候,測試的時候,遇到一個詭異的問題,在我有權限能access的機器們上面跑,就是有一台跑不起來,後來查了一下apache2的log才發現,原來是php suhosin module的問題,預設最大的POST及GET變數名稱最大只能夠是64字元,但是Picasa POST出去的卻遠超過,所以就被檔下來了。
解決方法很簡單,編輯/etc/php5/apache2/conf.d/suhosin.ini,加上下面這三行即可:
suhosin.request.max_varname_length=128
suhosin.get.max_name_length=128
suhosin.post.max_name_length=128
搞定收工。
http://advosys.ca/papers/web/62-php-hardening-suhosin.html
I've always compiled Suhosin with any of the Apache builds I've made in WHM on production/public servers. On every server CodeCall has been on, it has been there. The purpose of Suhosin is to protect servers and users from known flaws in PHP.
I never had a problem with it before. I've seen it strip variables and prevent server requests in the log files and it always seemed to help. Last night I ran into something annoying: Suhosin limits the character length for any request variable. It doesn't truncate the value as you might expect, it drops the variable completely.
I needed the ability to post considerably long string queries for ASCIIBin. For some reason the variables were being dropped and an empty BIN was being created. I couldn't figure out why. It worked fine on my test box (which didn't have suhosin) and I could see the data before actual POST using JavaScript. After some time I came to realize that Suhosin was the culprit.
The Fix
Taking a look at the documentation for Suhosin, you can figure out fairly quick that post.max_value_length is the configuration variable limiting character size.
The default character limit is 65,000.
Method 1: Obviously, you can just disable Suhosin to fix the problem. Remove the suhosin.o file from your php.ini config file and restart Apache.
Method 2: You probably want to keep Suhosin around so a different approach is to edit the configuration file. The file is named suhosin.ini, following the PHP ini configuration system. I added these lines:
suhosin.post.max_vars = 5000 suhosin.post.max_value_length = 500000 suhosin.request.max_vars = 5000 suhosin.request.max_value_length = 500000
Restart apache.
Method 3: Alternatively, you can change these values per user using .htaccess. Edit the .htaccess file in the user directory and set the parameters to what you want. Here is an example:
php_value suhosin.post.max_vars 5000 php_value suhosin.post.max_value_length 500000 php_value suhosin.request.max_vars 5000 php_value suhosin.request.max_value_length 500000
Conclusion
I hope this helps you if you ever run into the same situation. Perhaps it will save you some time. I know if there had been a post labeled "PHP POST character limit" and was indexed by google, I would have an hour of my time saved. Alas, there isn't so I'm making one.