From: http://blog.csdn.net/ricky1217/article/details/6934202
Reference: http://www.byreach.com/m/node/1439
The sameCodeIt is found that accessing through localhost/index. php is different from running through PHP./index. php In shell.
InProgramTo execute a Linux program through shell_exec, and its input comes from ECHO, that is:
Shell_exec('Echo '.Escapeshellarg($ Str). '| Some_cmd 2> & 1 ');
This $ STR may contain Chinese characters. At first, I thought it was some_cmd who filtered out the Chinese language. Later I found it was an issue with escapeshellarg.
It seems that there are not many such problems, so it's hard to find an article.Article: Http://byreach.com/m/node/1439. It turns out that the running environment of Shell and Apache PHP-CGI is different.
Add:
Setlocale(Lc_ctype, "utf8", "en_US.UTF-8 ");
Normal!
Bytes ------------------------------------------------------------------------------------------------------------
In the past, SOLR services were used to run the SOLR server on another machine and Java can be run. The performance of that machine is unstable now... The service cannot run, and the dream host machine does not want to run background service programs. The transformation was completed by running the Java program directly using the exec command of PHP to maintain the index of this site! Now the site search can be run independently. It is worth noting that when PHP runs the Java Virtual Machine, an error is reported, indicating that the memory space is insufficient. We need to test the problem and use the xmx option to control the memory size allocated by the virtual machine, after tests, there is no big problem in using M on this DH machine.
Passing parameters from PHP to Java programs is very exquisite. For example, the string to be indexed is passed through parameters, so there is an escape problem, and it cannot be too long. When using the PHP function escapeshellarg (), it is unexpectedly found that it will remove all Chinese characters, and the same code is correctly executed in the command line. I 'd like to think about it. It should be that the Lang environment variable has not been set. Someone found the same problem on the Internet:
Http://bonsai.php.net/bug.php? Id = 44945 & edit = 1
It seems that it is not feasible to deal with Shell and not to deal with this environment variable. We should use the method mentioned in it:
Setlocale (lc_ctype, "utf8", "en_US.UTF-8 ");
Change the default C to pass the parameter.