Skip to end of metadata
Go to start of metadata

Handling Errors

Basically there are two kind of errors you can expiricene when using this client: errors while trying to connect to a broker and errors after sending a certain command to the broker (like authorization errors for example). Also, there is a difference in how errors and hanlded in PHP4 and PHP5 compatible clients.

Broker Errors

In case you use the client (or at least the current operation) in a sychronous mode , the client will wait for the broker to send a receipt for every synchronous command. In case that error is received instead of the receipt, the client will report the error. In case you have sent a command in an asynchronous mode the erros will be ignored.


Since PHP4 doesn't support exceptions and it is not nice that library triggers fatal errors, there's a simple error handling approach implemented in PHP4 compatible Stomp client. A false value returned from the method call indicates an error. Also, there are two StompConnection class properties that holds error descriptions:

  • error contains a short description of the error
  • exception contains a full stack trace retruned from the broker (if applicable)

So, when you use PHP4 client, be sure that you always check a return value of the method call. Take a look at the folloing code snippet

PHP4 code sample

If used with ActiveMQ broker and try to send an unauthorized message it will return the following errors

  • error
    User guest is not authorized to write to: queue://test
  • exception
    java.lang.SecurityException: User guest is not authorized to write to: queue://test
            at org.apache.activemq.command.ActiveMQMessage.visit(
            at org.apache.activemq.transport.TransportFilter.onCommand(
            at org.apache.activemq.transport.stomp.StompTransportFilter.sendToActiveMQ(
            at org.apache.activemq.transport.stomp.ProtocolConverter.sendToActiveMQ(
            at org.apache.activemq.transport.stomp.ProtocolConverter.onStompSend(
            at org.apache.activemq.transport.stomp.ProtocolConverter.onStompCommad(
            at org.apache.activemq.transport.stomp.StompTransportFilter.onCommand(
            at org.apache.activemq.transport.TransportSupport.doConsume(
            at org.apache.activemq.transport.tcp.TcpTransport.doRun(
            at guest is not authorized to read from: queue://test