dongmimeng5500
2014-09-01 07:04
浏览 87
已采纳

为什么stomp不能在apache中运行?

  • Brief Intro

I'm now using stomp to connect with ActiveMQ based on a PHP site running on apache server. The Stomp can run in bash but can't run in apache.

  • Preparation

I install stomp by

pecl install stomp

and modify the php.ini with

extension=stomp.so

I have a 'index.php' like this:

<?php
echo 'runing-';
/* connection */
try {
    $stomp = new Stomp('tcp://localhost:61613');
    echo 'connecting-';
} catch(StompException $e) {
    die('Error! Connection failed: ' . $e->getMessage());
}
$stomp->send('/queue/test', 'Hello from PHP');
echo 'finished.';
/* close connection */
unset($stomp);
?>
  • Start Working

Firstly, I run with

$ php index.php

And it echo as my expectation:

$ php index.php
runing-connecting-finished.

Then I open it in browser:

http://localhost/index.php

It reports

runing-Error! Connection failed: Unable to connect to localhost:61613
  • Question

I've searching resolution for this error all day... I guess apache block the request from stomp since it runs successfully in bash.

What should I do to fix this bug?

Thanks really.

图片转代码服务由CSDN问答提供 功能建议

  • 简介

    我现在正在使用stomp来连接基于在apache服务器上运行的PHP站点的ActiveMQ。 Stomp可以在bash中运行但不能在apache中运行。

    • 准备工作

      我按

        pecl install stomp 
         
       
       

      并使用

        extension = stomp.so 
       <修改php.ini  / code>  
       
       

      我有一个像这样的'index.php':

       &lt;?php 
      echo'running-';  
       / * connection * / 
      try {
       $ stomp = new Stomp('tcp:// localhost:61613'); 
       echo'connection  - '; 
      } catch(StompException $ e){
       die  ('错误!连接失败:'。$ e-&gt; getMessage()); 
      } 
       $ stomp-&gt; send('/ queue / test','Hello from PHP'); 
      echo'已完成。  '; 
       / *关闭连接* / 
      unset($ stomp); 
      ?&gt; 
         
       
       
      • 开始工作< / strong>

        首先,我运行

          $ php index.php 
           
         
         

        它回应我的期望:

          $ php index.php 
        runing-connecting-finished。
           
         
         

        然后我在浏览器中打开它:

          http://localhost/index.php 
          <  / pre> 
         
         

        报告

          runing-Error! 连接失败:无法连接到localhost:61613 
           
         
         
        • 问题

          我整天都在搜索这个错误的解决方案...... 我猜apache会阻止来自stomp的请求,因为它在bash中成功运行。

          我该怎么办? 要解决这个问题吗?

          非常感谢。

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • duanfei9278 2014-09-01 09:29
    已采纳

    an experienced colleague called Justin get things done! Though not really understand this situation, I post my solution here:

    Firstly, I run sestatus:

    $ sestatus
    SELinux status:                 enabled
    SELinuxfs mount:                /selinux
    Current mode:                   enforcing
    Mode from config file:          enforcing
    Policy version:                 24
    Policy from config file:        targeted
    

    Justin told me to change settings in /etc/sysconfig/selinux to

    SELINUX=permissive
    

    Then I restart and run sestatus again:

    $ sestatus
    SELinux status:                 enabled
    SELinuxfs mount:                /selinux
    Current mode:                   permissive
    Mode from config file:          permissive
    Policy version:                 24
    Policy from config file:        targeted
    

    Finally things work!

    Linux stuff still seems a little magical for me. Who knows something about this please give an explanation about this.

    Thanks a lot.

    点赞 打赏 评论

相关推荐 更多相似问题