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

[PHP] Optimizing multiple I/O operations and catching errors

Options
  • 19-09-2010 10:54pm
    #1
    Registered Users Posts: 18


    Hi
    I am working on an upload system in php.
    Rather than try to explain it in english I'll just stick some pseudocode in here :o
    [PHP]
    input image (uploaded .jpg)
    input archive (uploaded .zip)

    if(validate input) {
    if(resize image and extract archive) {
    foreach(extacted file) {
    compare to array
    } else {handle resize/extract error}

    if(comparison to array ok) {
    if(insert to database ok) {
    if(update extracted file with auto increment id from db ok) {
    if(repackage zip ok) {
    if(post to phpbb ok) {
    if(update db with phpbb post id) {

    Everything went fine, proceed to next page

    } else {handle update db error}
    } else {handle post error}
    } else {handle repackage error}
    } else {handle update file error}
    } else {handle database error}
    } else {handle comparison error}
    } else {handle input error}
    [/PHP]

    Ok so hopefully you get the idea, the upload process only succeeds if every if(operation) succeeds.
    On to my question: Is there a 'better' way to handle errors during processing? The if() operations all return false if any error occurs during the sub operation. I've considered exceptions but because every operation relies on user input, any errors would be expected rather than exceptional.

    Error handling amounts to "set error=description of error, delete uploaded files, redisplay form with entered information"

    Memory/CPU usage are not an issue and the upload system shouldn't be getting much usage but if pushed how would you optimize this?

    Thanks for your time guys :)


Advertisement