Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

simple php question

Options
  • 09-07-2009 11:50pm
    #1
    Registered Users Posts: 8,070 ✭✭✭


    I have a process that retrieves info from the database then saves it to a txt file on the server then a mail function that emails that file.

    Now obviously the later part takes place at the end of the code, however is this how php works, will it let the data be accumulated completed first?

    im using php file methods, so print fclose at the end gives me '1'

    would it bebest practice to use something like

    $checker= fclose($fhandle);

    if($checker==1)
    {
    //send mail
    }


    thanks


Comments

  • Closed Accounts Posts: 5,857 ✭✭✭professore


    Placebo wrote: »
    I have a process that retrieves info from the database then saves it to a txt file on the server then a mail function that emails that file.

    Now obviously the later part takes place at the end of the code, however is this how php works, will it let the data be accumulated completed first?

    im using php file methods, so print fclose at the end gives me '1'

    would it bebest practice to use something like

    $checker= fclose($fhandle);

    if($checker==1)
    {
    //send mail
    }


    thanks

    you can just do

    if($checker)
    {
    //send mail
    }
    else
    {
    //print an error
    }

    or even ...

    if(fclose($fhandle))
    {
    //send mail
    }
    else
    {
    //print an error
    }


  • Registered Users Posts: 8,070 ✭✭✭Placebo


    so does fclose always equal something/integer on closing,
    i.e checker doesnt equal 0 if it didnt write/close properly ?

    also would you think there is a tiny ms/sec delay for the file to be properly set on the server, maybe i should use sleep just to be safe....


  • Registered Users Posts: 6,493 ✭✭✭daymobrew


    Placebo wrote: »
    so does fclose always equal something/integer on closing,
    i.e checker doesnt equal 0 if it didnt write/close properly ?

    also would you think there is a tiny ms/sec delay for the file to be properly set on the server, maybe i should use sleep just to be safe....
    fclose() returns TRUE or FALSE.
    If you are worried about the file being written to the disk, you can call fflush() before fclose().

    The operating system will ensure that the data is available for whatever you do after calling fclose() - that is its job!


Advertisement