server.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #!/usr/bin/env php
  2. <?php
  3. namespace tutorial\php;
  4. error_reporting(E_ALL);
  5. require_once("Config.inc.php");
  6. /*
  7. * Licensed to the Apache Software Foundation (ASF) under one
  8. * or more contributor license agreements. See the NOTICE file
  9. * distributed with this work for additional information
  10. * regarding copyright ownership. The ASF licenses this file
  11. * to you under the Apache License, Version 2.0 (the
  12. * "License"); you may not use this file except in compliance
  13. * with the License. You may obtain a copy of the License at
  14. *
  15. * http://www.apache.org/licenses/LICENSE-2.0
  16. *
  17. * Unless required by applicable law or agreed to in writing,
  18. * software distributed under the License is distributed on an
  19. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  20. * KIND, either express or implied. See the License for the
  21. * specific language governing permissions and limitations
  22. * under the License.
  23. */
  24. /*
  25. * This is not a stand-alone server. It should be run as a normal
  26. * php web script (like through Apache's mod_php) or as a cgi script
  27. * (like with the included runserver.py). You can connect to it with
  28. * THttpClient in any language that supports it. The PHP tutorial client
  29. * will work if you pass it the argument "--http".
  30. */
  31. if (php_sapi_name() == 'cli') {
  32. ini_set("display_errors", "stderr");
  33. }
  34. use Thrift\Protocol\TBinaryProtocol;
  35. use Thrift\Transport\TPhpStream;
  36. use Thrift\Transport\TBufferedTransport;
  37. use Thrift\TMultiplexedProcessor;
  38. use OpenSearch\Client\OpenSearchClient;
  39. use OpenSearch\Client\AppClient;
  40. use OpenSearch\Client\DocumentClient;
  41. header('Content-Type', 'application/x-thrift');
  42. if (php_sapi_name() == 'cli') {
  43. echo "\r\n";
  44. }
  45. $ak = '<your accessKey>';
  46. $secret = '<your secret>';
  47. $host = '<your endpoint>';
  48. $multiplexedProcessor = new TMultiplexedProcessor();
  49. $openSearchClient = new OpenSearchClient($ak, $secret, $host);
  50. $openSearchServiceProcessor = new \OpenSearch\Generated\OpenSearch\OpenSearchServiceProcessor($openSearchClient);
  51. $multiplexedProcessor->registerProcessor('opensearchServiceProcessor', $openSearchServiceProcessor);
  52. $appClient = new AppClient($openSearchClient);
  53. $appServiceProcessor = new \OpenSearch\Generated\App\AppServiceProcessor($appClient);
  54. $multiplexedProcessor->registerProcessor('appServiceProcessor', $appServiceProcessor);
  55. $documentClient = new DocumentClient($openSearchClient);
  56. $documentServiceProcessor = new \OpenSearch\Generated\Document\DocumentServiceProcessor($documentClient);
  57. $multiplexedProcessor->registerProcessor('documentServiceProcessor', $documentServiceProcessor);
  58. $transport = new TBufferedTransport(new TPhpStream(TPhpStream::MODE_R | TPhpStream::MODE_W));
  59. $protocol = new TBinaryProtocol($transport, true, true);
  60. $transport->open();
  61. $multiplexedProcessor->process($protocol, $protocol);
  62. $transport->close();