Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

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

  • 19-09-2010 10:54PM
    #1
    Registered Users, Registered Users 2 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