RestartController.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: shenyang
  5. * Date: 2018/10/28
  6. * Time: 下午6:16
  7. */
  8. namespace app\backend\modules\job\controllers;
  9. use app\common\components\BaseController;
  10. class RestartController extends BaseController
  11. {
  12. public function index()
  13. {
  14. $client = new XMLRPC_Client( "http://localhost:9001/RPC2" );
  15. $response = $client->call( 'mark.getUserMark');
  16. dd($response);
  17. }
  18. }
  19. class XMLRPC_Client {
  20. private $url;
  21. function __construct( $url ) {
  22. $this->url = $url;
  23. }
  24. /**
  25. * Call the XML-RPC method named $method and return the results, or die trying!
  26. *
  27. * @param string $method XML-RPC method name
  28. * @param mixed ... optional variable list of parameters to pass to XML-RPC call
  29. *
  30. * @return array result of XML-RPC call
  31. */
  32. public function call() {
  33. ini_set("display_error", 1);
  34. error_reporting(E_ALL);
  35. // get arguments
  36. $params = func_get_args();
  37. $method = array_shift( $params );
  38. $post = xmlrpc_encode_request( $method, $params );
  39. /*
  40. $post = str_replace("\n", "", $post);
  41. $post = str_replace(" ", "", $post);
  42. echo $post;
  43. */
  44. $ch = curl_init();
  45. // set URL and other appropriate options
  46. curl_setopt( $ch, CURLOPT_URL, $this->url );
  47. curl_setopt( $ch, CURLOPT_POST, true );
  48. curl_setopt( $ch, CURLOPT_POSTFIELDS, $post );
  49. curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
  50. // issue the request
  51. $response = curl_exec( $ch );
  52. $response_code = curl_getinfo( $ch, CURLINFO_HTTP_CODE );
  53. $curl_errorno = curl_errno( $ch );
  54. $curl_error = curl_error( $ch );
  55. curl_close( $ch );
  56. // check for curl errors
  57. if ( $curl_errorno != 0 ) {
  58. die( "Curl ERROR: {$curl_errorno} - {$curl_error}n" );
  59. }
  60. // check for server errors
  61. if ( $response_code != 200 ) {
  62. die( "ERROR: non-200 response from server: {$response_code} - {$response}n" );
  63. }
  64. // return $response;
  65. // $response .= 'e>';
  66. return xmlrpc_decode( $response );
  67. }
  68. }