Recently Learning es (elastic search), refer to the http://www.learnes.net/inside the official authoritative guide (later found that the official website has launched the Chinese version of the document). Some examples in this example simplify the command to access es as follows:
Curl-xget ' Localhost:9200/_count?pretty '-d ' { "query": { "Match_all": {}} } '//simplified to get/_count{ " Query ": { " Match_all ": {}} }
and the command line can not enter, so think of a way to write a script, read a command file, the file is a simplified command, converted into a complete command after execution. I could have chosen Python or the shell, but after all it was PHP, so I decided to write it in PHP. PHP executes external commands in several ways, using Popen before, and then using them this time. Then execute the command when prompted: Writing body failed.
At first I thought it was es the wrong, into the ES log, found no logs. And then think that is not the time to send a command to the JSON data into a string when there is a problem, confirm that the discovery is not, the following will know the description of Curl document. This is a standard error for the Curl command because curl cannot write local files. What file did Curl write? Naturally is the pipe file, change a way to call the Curl command, instead of the PHP system method, the problem is resolved.
On Curl's error, StackOverflow also asked, although I have not found the real reason, but found an example of the same error: https://stackoverflow.com/questions/16703647/ Why-curl-return-and-error-23-failed-writing-body.
Although the use of pipe sometimes causes curl to fail, ice beauty is clear about why it failed. But there is a case for a certain failure: the pipe has commands to exit before Curl writes, such as Grep-qs foo. grep exits and closes the pipe after it finds Foo.
Curl-x GET ' http://php.net/manual/zh/function.uniqid.php ' | grep -qs ' HTML '
Here need to choose a more content page, if you choose like ' www.baidu.com ' such a simple page, write pipe may be a one-time write out, will not error.
The Curl document can refer to http://aiezu.com/article/linux_curl_command.html.
Mark, please!
Curl cannot read and write to files