php 向 XMPP 服务器发送消息的函数不提供日志并且不起作用

php function that sends message to XMPP server give no log and doesn't work

我正在努力获得一个网页,用户可以在其中输入表单中的文本并单击提交。它从那里验证输入并将其发送到 php 函数,该函数使用 JAXL 3.0 库将消息发送到我的 XMPP 服务器。

我的问题是,当我调用 JAXL 函数时什么也没有发生。就像它无法完成该功能一样,因为下一个功能永远不会被调用。如果我交换其他函数的顺序,则会调用它,但它仍然没有完成 sendmessage() 函数。

我 rusty/new 在 php 中,我无法让 JAXL 提供日志或任何东西来调试我的问题所在。

如果有人知道如何正确调试这个 php/JAXL 函数,那将是一个很大的帮助。

我在网上四处搜索并查看了 JAXL 的示例,但找不到我的问题:/

编辑:尝试使用 ECHO 进行一些调试。如果 ECHO 发布在我的 Create 客户端下方,我将无法获取它。如果我在上面回声,它就可以工作。

我的发送消息功能:

function sendping()
  {
    //get the form elements and store them in variables
    $ping_text=$_POST["pingtext"];

    // Config Details
    $host = 'example.com';
    $user = 'host';
    $pass = 'password';

    // Create Client
    $client = new JAXL(array(
      'log_path' => '/var/log/jaxl.log',
      'jid' => $user.'@'.$host,
      'pass' => $pass,
      'log_level' => JAXL_INFO,
      'auth_type' => 'PLAIN'
    ));

    // Add Callbacks
      $client->add_cb('on_auth_success', function() use ($host, $client, $ping_text) {
      $client->send_chat_msg($host.'/announce/online', $ping_text);
      $client->send_end_stream();

    });
    $client->add_cb('on_auth_failure', function($reason) use ($client)
    {
      $client->send_end_stream();
      _info("got on_auth_failure cb with reason: $reason");
    });
    $client->add_cb('on_disconnect', function() use ($client)
    {
      _info("got on_disconnect cb");
    });
    // Startup Client
    $client->start();

我的洞.php页面:

<?php
/*
Template Name: Stahp Ping
*/

require 'jaxl.php';

get_header(); ?>

<div id="hidden_div" style="display:none; margin-left:auto; margin-right:auto; margin-top:20px;
text-align:center;">
<p>Ping has been sent </p>
</div>

<div style="width:850px !important;
margin-left:auto;
margin-right:auto;
margin-top:20px;
text-align:center;" id="pingform">


<form action="<?php echo htmlspecialchars($_SERVER['REQUEST_URI']);?>" method="post" name="stahpbox">
<textarea name="pingtext" rows="8" cols="60"></textarea>
<input type="submit" value="Send Ping" />
</form>

</div>

<script type="text/javascript">
 function showHide() {
   var div = document.getElementById("hidden_div");
   var pingdiv = document.getElementById("pingform");
   if (div.style.display == 'none') {
     div.style.display = '';
     pingdiv.style.display='none';
   }
   else {
     div.style.display = 'none';
     pingdiv.style.display = '';
   }
 }
</script>

<?php
function sendping()
  {
    //get the form elements and store them in variables
    $ping_text=$_POST["pingtext"];

    // Config Details
    $host = 'example.com';
    $user = 'user';
    $pass = 'password';

    // Create Client
    $client = new JAXL(array(
      'log_path' => '/var/log/jaxl.log',
      'jid' => $user.'@'.$host,
      'pass' => $pass,
      'log_level' => JAXL_INFO,
      'auth_type' => 'PLAIN'
    ));

    // Add Callbacks
      $client->add_cb('on_auth_success', function() use ($host, $client, $ping_text) {
      $client->send_chat_msg($host.'/announce/online', $ping_text);
      $client->send_end_stream();

    });
    $client->add_cb('on_auth_failure', function($reason) use ($client)
    {
      $client->send_end_stream();
      _info("got on_auth_failure cb with reason: $reason");
    });
    $client->add_cb('on_disconnect', function() use ($client)
    {
      _info("got on_disconnect cb");
    });
    // Startup Client
    $client->start();
  }

//Validation and redirection to send to jabber
// Initialize variables and set to empty strings
$pingtextERR="";
// Validate input and sanitize
if ($_SERVER['REQUEST_METHOD']== "POST") {
  $valid = true; //Your indicator for your condition, actually it depends on what you need. I am just used to this method.

  if (empty($_POST["pingtext"])) {
      $pingtextERR = "Text is required";
      $valid = false; //false
      echo "<script type='text/javascript'>alert('$pingtextERR');</script>";
  }
 //if valid then redirect
  if($valid){
  echo "<script> showHide(); </script>";
  sendping();
  }
}

?>

显然问题是 PLAIN 授权。不适用于 JAXL,因此将其更改为另一个 AUTH,并且工作正常。