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

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

本文关键字:日志 不起作用 消息 函数 XMPP 服务器 php      更新时间:2023-09-26

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

我的问题是,当我调用JAXL函数时,什么都不会发生。就好像它无法完成这个函数,因为下一个函数永远不会得到它的调用。如果我在调用其他函数时交换顺序,但它仍然没有完成sendmessage()函数。

我对php很陌生,无法让JAXL提供日志或任何东西来调试我的问题所在

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

我在网上搜索了一下JAXL的例子,但找不到我的问题:/

编辑:尝试使用ECHO进行一些调试。如果ECHO发布在我的Create客户端下面,我就无法获得它。如果我在上面ECHO,它就行了。

我的发送消息功能:

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();

我的hole.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 auth。不适用于JAXL,所以将其更改为另一个AUTH,效果良好。