We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 13443
    • 1 Posts
    Hi,

    I’m writing a snippet which incorporates the following code:
    $this->handle = @fsockopen($this->address, $this->port, $errno, $errstr, 1);


    Now, if there is no answer on this socket I get an error when modx runs the snippet saying that:
    [tt]« MODx Parse Error »
    MODx encountered the following error while attempting to parse the requested resource:
    « PHP Parse Error »

    PHP error debug
    Error: fsockopen(): unable to connect to localhost:5160[/tt]

    However, I would like the snippet to output an error message of my choice, which it does, but because of the error it is never shown.

    Is there another way of doing this in modx?

    Regards
    Jonas
      • 22303 MODX Staff
      • 10,725 Posts
      This really shouldn’t have anything to do with MODx -- http://www.php.net/function.fsockopen -- according to the docs, fsockopen should just return false if it fails. I don’t think you even need the @ operator here, but I can’t explain why the PHP error is getting triggered.
        • 28042 ☆ A M B ☆
        • 24,524 Posts
        I’ve noticed many instances where the MODx error handling overrides the core php error handling. I haven’t been able to figure out a way to override the MODx error handling!
          Studying MODX in the desert - http://sottwell.com
          Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
          Join the Slack Community - http://modx.org
          • 11979
          • 8 Posts
          Quote from: OpenGeek at Mar 22, 2006, 11:31 AM

          This really shouldn’t have anything to do with MODx -- http://www.php.net/function.fsockopen -- according to the docs, fsockopen should just return false if it fails. I don’t think you even need the @ operator here, but I can’t explain why the PHP error is getting triggered.

          confused here to huh

          # create socket & connect to server
          $fp = fsockopen($host, $port, $errno, $errstr, $timeout);
          
          # check for error in connection
          if (!$fp)
           { $error_message = "<strong>fsockopen() | </strong> Error: Connection Timeout...'.";
             $modx->logEvent(0, 3, $error_message, 'RadioController');
             return $debug ? $error_message : '';
           }
          
          # no errors connecting, continue
          else
           { #my connection code  
           
          


          i see MODx Parser error page when this function fails...also the logEvent() never makes it to the system event log...

          pages
          http://beta.remotehams.com/fsock_error.html - forced error
          http://beta.remotehams.com/radio-reader.html - page without error > fsock didn’t fail