1

I've checked number of solutions and none have solved my problem. So, decided to open another issue with pretty common error.

My code:

<?php
/**
 * Created by PhpStorm.
 * User: max
 * Date: 04.05.17
 * Time: 13:51
 */


?>

<div class="modal-header bg-box">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="false">x</button>
        <table class="modal-action-header">
            <tbody>
            <tr>
                <td class="modal-action-title">

                    <h2 class="modal-title">
                        <i class="fa pe-7s-credit"></i>
sexybox Transaction
</h2>
                </td>
                <td>

                </td>
            </tr>
            </tbody>
        </table>
    </div>
    <div class="modal-body">
        <div class="modal-content-gridview">
            <h3>sexybox Transaction</h3>
            <div class="broadcast-content">
                <div class="text-center">
                    <?php
                    if (count($model->errors)) {
                        foreach ($model->errors as $errorName => $errorMsgs) {
                            ?>
                            <section class="panel panel-featured-left panel-featured-secondary">
                                <div class="panel-body">
                                    <div class="widget-summary widget-summary-sm">
                                        <div class="widget-summary-col widget-summary-col-icon">
                                            <div class="summary-icon bg-secondary">
                                                <i class="fa"></i>
                                            </div>
                                        </div>
                                        <div class="widget-summary-col">
                                            <h4 class="title"><?= ucwords(strtolower($errorName)); ?></h4>
                                            <div class="summary">

                                                <?php
                                                foreach ($errorMsgs as $errorMsg) {
                                                    ?>
                                                    <div class="info">
                                                        <strong class="amount"><?= $errorMsg; ?></strong>
                                                    </div>
                                                    <?php
                                                }
                                                ?>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </section>
                            <?php
                        }
                    }
                    ?>

    <section class="panel panel-featured-left panel-featured-primary">
        <div class="panel-body">
            <label class="sexybox-type">
                <ul>
                    <li><input type="radio" name="sexyboxType" id="fullsexybox" value="full"  onclick="js:$('#sexyboxValueBlock').hide();" /></li>
                    <li>
                        <div><h5>Full sexybox</h5></div>
                        <div>sexybox the full amount(<?=$model->amountNetFormatted; ?>)</div>
                    </li>
                </ul>
            </label>
            <label class="sexybox-type">
                <ul>
                    <li><input type="radio" name="sexyboxType" id="partialsexybox" value="partial" onclick="js:$('#sexyboxValueBlock').show();" /></li>
                    <li>
                        <div><h5>Partial sexybox</h5></div>
                        <div>sexybox a partial amount</div>
                    </li>
                </ul>
            </label>
            <label id="sexyboxValueBlock" style="display: none;" class="sexybox-type">
                <ul>
                    <li class="sexybox-amount-text"><h5>sexybox amount:</h5></li>
                    <li class="sexybox-amount-box"><?=$currency;?> <input type="text" name="sexyboxValue" id="sexyboxValue" /></li>
                </ul>
            </label>
        </div>
    </section>
<?=
                    Html::hiddenInput("transId", $model->id, [
                        'id' => "transId"
                    ]);
                    ?>
    </div>
    <div class="text-center">
        <div class="text-right form-buttons">
            <?=
            Html::button(
                'Cancel', [
                    'class' => 'btn btn-cancel',
//                                'style' => 'float:left;',
                    'onclick' => 'js:boxModalPopover.modal(\'hide\');'
                ]
            );
            ?>

            <?=
            Html::button(
                'sexybox', [
                    'class' => 'btn btn-info',
//                                'style' => 'float:left;',
                    'onclick' => 'js:$.ajaxsexybox();'
                ]
            );
            ?>
        </div>
    </div>
    </div>
    </div>
    </div>
    <div class="alert-defaults" style="display: none;">
    </div>
<?php

I get error

FastCGI-stderr: PHP message: PHP Parse error: syntax error, unexpected end of file in on one ubuntu box not another that is exactly the same. The file is checked from git on both machines and I've been hitting my head against a wall on why it works on box and another.

Here is the strange thing on the box that it doesn't work when I open a file and resave it then it start working. Essentially there is no lf or crlf in the file, but it works on one of the boxes. What could it be ?

Environment config:

  • php 5.5.9 release 17
  • ubuntu 14
  • lighttpd
Cac3a
  • 117
  • 1
  • 10
  • 2
    Possible duplicate of [PHP Parse/Syntax Errors; and How to solve them?](https://stackoverflow.com/questions/18050071/php-parse-syntax-errors-and-how-to-solve-them) – aynber Jun 21 '17 at 20:06
  • Try opening the file in a text editor such as vim when it's having an issue. I'm betting there's some invisible characters (`^M`) that you can't normally see. – aynber Jun 21 '17 at 20:08
  • @aynber his problem is not a general parse error. His script parses correctly, it's a run time issue where apache hits a timeout and cuts off the remaining script. – Matt Jun 21 '17 at 20:12
  • The thing is that I checkout the same file on both machines directly from git and it works on 1 and not the other. If it was ^M character would it break it both places. – Cac3a Jun 21 '17 at 20:20

2 Answers2

0

You are hitting the FCGI timeout or crash which cuts off the script on the exact line when it hits the issue.

Your web server error log will probably confirm this depending on how you're setup.

Also, on each server, from the command line you can test for syntax errors by running: php -l <filename>

Matt
  • 5,315
  • 1
  • 30
  • 57
  • Every single time I run the page it hits at the exactly same time? I find it hard to believe. – Cac3a Jun 21 '17 at 20:16
  • Why is it hard to believe? It is probably in the middle of an intensive call every single time it hits the timeout. That particular call is probably where 99% of your script execution time is spent. Scatter some error_log calls throughout and see if it gets to the same spot each time. – Matt Jun 21 '17 at 20:17
  • @Cac3a I've updated my answer with a way to manually check that php can parse your file on all the environments. – Matt Jun 21 '17 at 20:20
  • php -l produces No syntax errors detected in...It does break at the same point every time. Like in my original question when I resave the file it works fine, it only break after I check it out from git. But then when its chcked out on both machines and one works and the other doesn't. – Cac3a Jun 21 '17 at 20:23
  • You probably need to update your question with all the environment details (OS, web server, php, versions of everything) where it works and where it doesn't. I'd also run `md5sum()` from command line before and after it breaks to be certain that nothing is modifying the file in between. Also simplify it. Make it the smallest possible example where it breaks. Remove chunks of the file until it passes. etc. – Matt Jun 21 '17 at 20:45
  • I wonder if it's something like a UTF-8 BOM that's choking FCGI and when you save it, your editor is removing it. Is it the same version of git in each environment? – Matt Jun 21 '17 at 20:55
  • Same version of git 1.9.1 – Cac3a Jun 21 '17 at 21:00
  • Are you able to update PHP? You aren't too far behind but there are a lot of bug fixes between where you're at and 5.6.30 – Matt Jun 21 '17 at 21:01
  • I could try, but too much testing to make sure everything works. The thing that I go back is how is it possible that it works on one. Also, just ran php -l -c fpm-php.ini file_name produces the error on one box. Same command works on the other box. I compared the two fpm-php.ini files on both boxes and they are the same. – Cac3a Jun 21 '17 at 21:04
  • Can you turn on/off mcrypt to make both envs the same? To see if that does have an effect? – Matt Jun 21 '17 at 21:05
  • Turned off mcrypt on working box and it continues to work. The only difference is the patch 17(not working box) vs 20 (working box) between two boxes. I won't be able to update 17 to 20 until tonight though as that is prod server. – Cac3a Jun 21 '17 at 21:07
  • Do you get the same md5sum on the file before/after save? – Matt Jun 21 '17 at 21:12
  • md5sum did change after saving it. It matches 1 to 1 on both machines for prior saving and after saving. – Cac3a Jun 21 '17 at 21:39
  • I'm really curious if it has a BOM before or after. You might try the solution here to detect BOM: https://unix.stackexchange.com/questions/170775/how-to-check-if-file-has-a-bom-in-utf-8-text#170776 – Matt Jun 21 '17 at 21:41
  • You could also write a PHP script to detect if another script has a BOM: https://anupamsaha.wordpress.com/2011/08/02/detecting-utf-byte-order-mark-using-php/ – Matt Jun 21 '17 at 21:45
  • I ran `file file_name.php` and it produced `PHP script, ASCII text` both before and after the save of the file – Cac3a Jun 21 '17 at 21:49
  • Try: `/usr/bin/printf "\ufeff...\n" | file ` – Matt Jun 21 '17 at 21:50
  • I'm perplexed. I'll be interested to hear what it is if you figure it out. You could try some of this stuff: https://stackoverflow.com/questions/2517190/how-do-i-force-git-to-use-lf-instead-of-crlf-under-windows#13154031 – Matt Jun 21 '17 at 21:51
  • Ran the command you suggested and got the same out as from just file command `PHP script, ASCII text` – Cac3a Jun 21 '17 at 21:57
  • You said it is consistently breaking at the same place every time, which line is it? – Matt Jun 21 '17 at 22:02
  • Last line of the file ` – Cac3a Jun 21 '17 at 22:11
  • I understand why they're doing it but what happens if you remove that line? – Matt Jun 21 '17 at 22:35
  • https://serverfault.com/questions/784918/php-parse-error-syntax-error-unexpected-end-of-file – Matt Jun 21 '17 at 22:37
0

What a bizarre problem, but here is what I just did. Upgraded php 5.5.9 to latest patch 21. Pulled all files from git as I did before and everything works fine. In my opinion if you have php 5.5.9-patch17 and short tags On and file with

Thanks for help guys.

Cac3a
  • 117
  • 1
  • 10