Trouble with pg_connect in connecting to Heroku - php

I created a PHP app on Heroku and I'm trying to connect to a Postgres database I set up on Heroku.
I put a snippet like this into the project:
$dbconn = pg_connect("host=thehost.amazon.whatever port=1010 dbname=blahblah user=jooghaha password=foofoo sslmode=require options='--client_encoding=UTF8'") or die('Could not connect: ' . pg_last_error());
However, when I try to request the file in the app, the server returns a generic HTTP 500 Error, and the Heroku logfiles say
PHP Parse error: syntax error, unexpected T_VARIABLE, expecting ',' or ';' in /app/www/pages/database.php on line 23
Any ideas?

The one line you posted looks fine. Assuming that line is really line 23 of /app/www/pages/database.php, you should look at the surrounding few lines to find the parse error. Often, PHP is not so precise at telling you where a syntax error is. Look in particular for unbalanced parentheses, missing semicolons, etc. in the lines above that snippet.

Related

Parse Error PHP Encapsed String in Magento Module

Receiving the following error while trying to register a custom Magento2 module on my local machine:
Parse error: syntax error, unexpected ''DDF_AdminMenu''
(T_CONSTANT_ENCAPSED_STRING), expecting ')' in
/Users/petey/Desktop/magento/app/code/DDF/AdminMenu/registration.php
on line 5
I can't seem to understand why I'm getting the error.
My code is the following:
\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'DDF_AdminMenu',
    __DIR__
);
I know this may seem obvious but it happened to me
Please make sure you add <?php at the beginning of the file

php application fail with Apache server (Wordpress, phpMyAdmin and Squirrrelmail)

Yesterday my Apache installation stopped working with PHP applications like Wordpress, phpMyAdmin and Squirrelmail.
The problem is that Apache-php chokes on lines containing the "global" statement.
The Wordpress error looks like this:
PHP Parse error: syntax error, unexpected '$error' (T_VARIABLE) in /var/www/html/XXXXXXX/wordpress/wp-login.php on line 34
Line 34 contains the "global" statement:
global $error, $interim_login, $action;
Similar in phpMyAdmin:
PHP Parse error: syntax error, unexpected '$text_domains' (T_VARIABLE) in /usr/share/php/gettext/gettext.inc on line 47
Line 47 also includes the global statement:
global $text_domains, $default_domain, $LC_CATEGORIES, $EMULATEGETTEXT, $CURRENTLOCALE;
If I comment out the line PHP just fails on the next line including the "globa"l statement.
I tried to execute the file using php command line and it finishes without any error.
The latest software upgrades doesn't seem to be related.
iwl100-firmware
iwl1000-firmware
iwl105-firmware
iwl135-firmware
iwl2000-firmware
iwl2030-firmware
iwl3160-firmware
iwl3945-firmware
iwl4965-firmware
iwl5000-firmware
iwl5150-firmware
iwl6000-firmware
iwl6000g2a-firmware
iwl6000g2b-firmware
iwl6050-firmware
iwl7260-firmware
libappstream-glib
libertas-usb8388-firmware
linux-firmware
opus
rpcbind
tzdata
tzdata-java
webkitgtk4
webkitgtk4-jsc
webkitgtk4-plugin-process-gtk2
Hoping that someone has a clue.
Thanks
John

E_PARSE errors only showing in New Relic in Laravel 5.0

I have a weird not so helpful error in New Relic. These errors are not showing in Laravel logs OR in raw php logs. For example :
Error message
E_PARSE: syntax error, unexpected '\Foundatio', expecting \\ (T_NS_SEPARATOR) or ';' or '{'
Sample stack trace
in require called at /home/xxx/public_html/bootstrap/autoload.php (32)
in require called at /home/xxx/public_html/public/index.php (36)
or
Error message
E_PARSE: syntax error, unexpected '\Support {', expecting \\ (T_NS_SEPARATOR) or ';' or '{'
Sample stack trace
in require called at /home/xxx/public_html/bootstrap/autoload.php (32)
in require called at /home/xxx/public_html/public/index.php (36)
or
Error message
E_PARSE: syntax error, unexpected '\Compon', expecting \\ (T_NS_SEPARATOR) or ';' or '{'
Stack trace
in require called at /home/xxx/public_html/bootstrap/autoload.php (32)
in require called at /home/xxx/public_html/public/index.php (36)
These errors seem to happen everytime I run a composer install on the server. The times of my commit/deployment seem to match the time of the errors in New Relic.
Any idea what this can be, and why I don't get them in the logs but they show up in New Relic ?
Thanks a lot for your help
The errors don't show in Laravel logs because Laravel is not even run. Parse errors are detected when a file is loaded and the file does not get executed.
Thanks to #jerdrzej I realized I was being a bit reckless.
If anyone has this issue, solution is to use a proper way to deploy your code (the user only gets to see the new code if everything went well with the deployment -- NO DOWNTIME).
I use dploy.io and with their last update (they changed the name to DeployBot) they can do that :
http://deploybot.com/
Or there is Envoyer from the Laravel team :
https://envoyer.io/
There are probably other way to avoid the downtime, but this will work for me.

Sudden PHP parse error on RHEL

I have various PHP files, none of which have been modified prior to the app working and it breaking. My problem is that for some reason, these files are suddenly throwing PHP parse errors for things like 'unexpected' square brackets in seemingly random places throughout the file, but upon manually checking the file, the syntax is correct.
The only thing I did that could have 'altered' the files would be various chmod operations to change the permissions. But how/why would this change the actual content of the files?
The files are called on boot just as they always have been, and have worked fine in the past, up until the recent chmod changes.
Is this permanent, or will I just have to restore my system from an earlier time?
RHEL 6.5, PHP 5.4.
Edit:
Example of the error:
PHP Parse error: syntax error, unexpected '[' in /var/ptc/CRM-dev/tools/init on line 122
What's on line 122:
$files = [];
Another example:
PHP Parse error: syntax error, unexpected '[', expecting ')' in /var/ptc/CRM-dev/vendor/react/promise/src/functions.php on line 68
What's on line 68:
return resolve([]);
But these files themselves haven't been changed (as far as I'm aware), and the syntax looks correct.
phpinfo() gives 5.4.39, which is the same as when running php -v on the server.
If the PHP version has been changed then it may be stumbling on the PHP 5.4 square bracket array syntax.
Use phpinfo(); to be sure that the PHP version running the web server is the same as the one you're using on the CLI.

PHP adding value to array

In PHP why is this a syntax error:
$row['some_key'] = "kkkk";
Raises
Parse error: syntax error, unexpected T_STRING
From the documentation I understood this to be perfectly valid PHP, yet it throws the same error every time (and the error of course goes away then I comment the line out).
Edit: After long searching I actually noticed that the file is indeed corrupted in some way. In Vim (on ubuntu 12.04) the file looks just normal. But when viewing from other computers it's corrupted. So not related to PHP.
In PHP why is this a syntax error:
It's not. If you're getting unexpected T_STRING, the problem is elsewhere (hint: look at the line above).

Categories