Error with fopen() function

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • chazzy69
    New Member
    • Sep 2007
    • 196

    Error with fopen() function

    So the function fopen() works most of the time heres the line im using-

    Code:
     
    $file = fopen($nextPage, "r") or exit("Unable to open file!");
    But for some reason that i haven't been able to discern yet im getting "Unable to open file!" on specific urls this wouldn't be so much of a problem but it ends up hanging the rest of the program up.

    Anyway so far i cant see any reason for the errors to occur becuase when theres a error i manually type in the url into a browser it works fine even though im getting a connection error.

    So if anyone can help understand why there is an error occuring or better yet a way to skip a function if a error occurs.

    Oh yer even if i continually repeat the the function i still get a connection error over and over again so i doesn't seem to be just a single random error.

    Any helps with this problem is greatly appreciated,

    Thanks in advance,
  • dlite922
    Recognized Expert Top Contributor
    • Dec 2007
    • 1586

    #2
    Originally posted by chazzy69
    So the function fopen() works most of the time heres the line im using-

    Code:
     
    $file = fopen($nextPage, "r") or exit("Unable to open file!");
    But for some reason that i haven't been able to discern yet im getting "Unable to open file!" on specific urls this wouldn't be so much of a problem but it ends up hanging the rest of the program up.

    Anyway so far i cant see any reason for the errors to occur becuase when theres a error i manually type in the url into a browser it works fine even though im getting a connection error.

    So if anyone can help understand why there is an error occuring or better yet a way to skip a function if a error occurs.

    Oh yer even if i continually repeat the the function i still get a connection error over and over again so i doesn't seem to be just a single random error.

    Any helps with this problem is greatly appreciated,

    Thanks in advance,
    This is generally a basic function. There's not much code there to "help" you debug. All you need to do is check to make sure the $nextPage variable is going to a correct path. It wouldn't hurt to just echo that variable.

    As far as the exiting when a function fails, this is PHP default fault exception behavior. PHP exits when a fatal error occurs, whether or not display_errors is on. You need to remove that "or exit(....)" part (because that exits the processes if the function returns false or errors) and then put a @ sign infront of the function to suppress that function (such as @fopen() )

    Hope that helps,




    Dan

    Comment

    • chazzy69
      New Member
      • Sep 2007
      • 196

      #3
      Error with fopen() function

      Thanks ill try that out

      Comment

      • chazzy69
        New Member
        • Sep 2007
        • 196

        #4
        Error with fopen() function

        Ok just have one question when you said put @ in front of the function call to suppress it is this supposed to be at run time (when it compiles) or before??

        Also i don't suppose there is a goto command in php??

        Thanks for the help

        Comment

        • pbmods
          Recognized Expert Expert
          • Apr 2007
          • 5821

          #5
          Heya, Chazzy.

          The '@' operator suppresses any errors that a PHP statement generates (PHP: Error Control Operators - Manual).

          Generally, you will see this error if Apache does not have read permissions for the file you're trying to open.

          Comment

          • chazzy69
            New Member
            • Sep 2007
            • 196

            #6
            Oh sweet thanks i get it now

            Comment

            • chazzy69
              New Member
              • Sep 2007
              • 196

              #7
              I fixed the problem thanks for your help pplz

              Comment

              Working...