Stopping Parse errors appearing on a Site Whilst Uploading

Discussion in 'PHP' started by misohoni, May 14, 2014.

  1. #1
    It's not a problem per say, but it is an annoyance and I was wondering if there was a solution.

    For example, if I'm uploading a php file - sometimes the connection speed it slow and I try to access the file I get this:
    Parse error: syntax error, unexpected + the site location of the file.

    Is there any php code I can use so this parse error doesn't appear live on the site whilst uploading?
     
    misohoni, May 14, 2014 IP
  2. misohoni

    misohoni Notable Member

    Messages:
    1,717
    Likes Received:
    32
    Best Answers:
    0
    Trophy Points:
    200
    #2
    Yes trying to access it whilst uploaded. If I used that solution then there would be a delay/blank page deleting the old (index.php) file before renaming the new one...I don't think that would work plus I make many changes per day to the file.
     
    misohoni, May 14, 2014 IP
  3. misohoni

    misohoni Notable Member

    Messages:
    1,717
    Likes Received:
    32
    Best Answers:
    0
    Trophy Points:
    200
    #3
    Thanks but it's not compatible with my setup, out of interest which software do you use as my FTP setup won't allow me to rename a file if an existing file already has that name...
     
    misohoni, May 14, 2014 IP
  4. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #4
    Just out of curiosity - how big is your index.php, or how crappy is your Internet speed if this is actually a problem? An index.php should upload in a couple seconds, at most.
     
    PoPSiCLe, May 14, 2014 IP
  5. misohoni

    misohoni Notable Member

    Messages:
    1,717
    Likes Received:
    32
    Best Answers:
    0
    Trophy Points:
    200
    #5
    I upload via FTP, it's Dreamweaver or something else - the file is an index.php file, uploading it as new-index.php and the renaming it to index.php won't work for me.

    The actual index.php file is about 250kb, but the file runs the whole site/pages.
     
    misohoni, May 14, 2014 IP
  6. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #6
    Okay. A quarter of a MB for an index file is kinda insane. You should really look into how this is coded, and perhaps put some functionality in class files or separate functions. Seems a bit much.
     
    PoPSiCLe, May 14, 2014 IP
  7. misohoni

    misohoni Notable Member

    Messages:
    1,717
    Likes Received:
    32
    Best Answers:
    0
    Trophy Points:
    200
    #7
    Okay I'll look into it, the site is pretty quick though and things are called as/when they're needed...
    For Neroux answer, wondering if that's the best solution DP can offer?!
     
    misohoni, May 14, 2014 IP
  8. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #8
    Don't use Dreamweaver, seriously. It's corporate garbage. Try using another FTP client, there are lots of free (and better) ones.

    Try using a different FTP daemon on the server side. ProFTPD, etc...

    Or ditch FTP altogether and use Git.

    Although, @PoPSiCLe has a point. Your index.php file should bootstrap your site, and not contain everything. Try spreading your code over a few more files, and include these whenever you need them.
     
    nico_swd, May 14, 2014 IP
  9. ThePHPMaster

    ThePHPMaster Well-Known Member

    Messages:
    737
    Likes Received:
    52
    Best Answers:
    33
    Trophy Points:
    150
    #9
    This will happen no matter what. Filesize has nothing to do with it. All companies that I have worked with (even small ones) create a maintenance.html page, which while the updates to the website occur, it gives the users a nice message "Our website is being updated, please try again in a few minutes". Here is an example of how it could be done: http://davidwalsh.name/htaccess-maintenance-page-redirect
     
    ThePHPMaster, May 15, 2014 IP
  10. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #10
    Yes, it will happen no matter what, but you can reduce the file size to decrease the amount of time. If there's a two second gap while you upload the file, it's not a big deal.
     
    PoPSiCLe, May 15, 2014 IP
  11. O-D-T

    O-D-T Member

    Messages:
    180
    Likes Received:
    10
    Best Answers:
    3
    Trophy Points:
    43
    #11
    I'm not sure if you always upload only index.php but it seems so. In that case you can (by a batch script):

    1) upload new-index.php
    2) delete index.php
    3) rename new-index.php

    It should be still faster than simply uploading new 'index.php' file.

    Or you can change your index.php script like this:
    <?php
    
    if (file_exists(__DIR__ . '/maintenance.txt')) {  // or for example: file_get_contents(__DIR__ . '/maintenance.txt') ==="yes"
        echo "The site is in maintenance mode.";
    } else {
        include __DIR__ . '/your-original-index.php';
    }
    PHP:
    I personally prefer deployment via git (for example http://krisjordan.com/essays/setting-up-push-to-deploy-with-git) but some setup is needed. Yet, it's definitely worth it.
     
    O-D-T, Jun 8, 2014 IP