client.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace tutorial\php;
  3. error_reporting(E_ALL);
  4. require_once("Config.inc.php");
  5. use Thrift\ClassLoader\ThriftClassLoader;
  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. use Thrift\Protocol\TBinaryProtocol;
  25. use Thrift\Transport\TSocket;
  26. use Thrift\Transport\THttpClient;
  27. use Thrift\Transport\TBufferedTransport;
  28. use Thrift\Exception\TException;
  29. use Thrift\Protocol\TMultiplexedProtocol;
  30. use OpenSearch\Generated\Common\Pageable;
  31. try {
  32. if (array_search('--http', $argv)) {
  33. $socket = new THttpClient('localhost', 8080, '/php/server.php');
  34. } else {
  35. $socket = new TSocket('localhost', 9090);
  36. }
  37. $transport = new TBufferedTransport($socket, 1024, 1024);
  38. $protocol = new TBinaryProtocol($transport);
  39. $transport->open();
  40. $clientProtocol = new TMultiplexedProtocol($protocol, 'openSearchServiceProcessor');
  41. $client = new \OpenSearch\Generated\OpenSearch\OpenSearchServiceClient($clientProtocol);
  42. $appProtocol = new TMultiplexedProtocol($protocol, 'appServiceProcessor');
  43. $appClient = new \OpenSearch\Generated\App\AppServiceClient($appProtocol);
  44. /*$pageable = new Pageable(array('page' => 1, 'size' => 1));
  45. $ret = $appClient->listAll($pageable);*/
  46. $ret = $appClient->save('test');
  47. print_r($ret);
  48. $transport->close();
  49. } catch (TException $tx) {
  50. print 'TException: '.$tx->getMessage()."\n";
  51. }
  52. ?>