Problems with JSON and PHP
Doug Hardie
bc979 at lafn.org
Sat Feb 2 01:31:45 UTC 2019
> On 1 February 2019, at 14:26, Doug Hardie <bc979 at lafn.org> wrote:
>
>> On 1 February 2019, at 07:24, Mark Moellering <markmoellering at psyberation.com> wrote:
>>
>> On Fri, Feb 1, 2019 at 10:17 AM <freebsd at boosten.org> wrote:
>>
>>>>> test# more /usr/local/www/apache24/data/test.php
>>>>> <?php
>>>>> print "Hello world";
>>>>>
>>>>> $myObj = (object) array();
>>>>> $myObj->name = "John";
>>>>> $myObj->age = 30;
>>>>> $myObj->city = "New York";
>>>>>
>>>>> $myJSON = json_encode($myObj);
>>>>>
>>>>> echo $myJSON;
>>>>> ?>
>>>>>
>>>>>
>>>>> I use php and my biggest complaint is the way it handles errors. I
>>> think
>>>> what is happening is that your Object Definition has a syntax error but
>>> php
>>>> is complaining about the json_encode.
>>>> I believe (from the php.net docs) that it should be
>>>>
>>>> $myObj = new stdClass();
>>>>> $myObj->name = "John";
>>>>> $myObj->age = 30;
>>>>> $myObj->city = "New York";
>>>>>
>>>>
>>>
>>> Don’t believe that’s actually the issue, since the supplied test.php works
>>> like charm for me, either in my browser (through apache) or via command
>>> line.
>>>
>>> If it were the declaration, the command line would fail as well.
>
> The initial issue is with a very large package. The example I provided was the simplest I could come up with that showed the issue. I ran php -init and the output (partial) was:
>
> Server API => Command Line Interface
> Virtual Directory Support => disabled
> Configuration File (php.ini) Path => /usr/local/etc
> Loaded Configuration File => /usr/local/etc/php.ini
> Scan this dir for additional .ini files => /usr/local/etc/php
> Additional .ini files parsed => /usr/local/etc/php/ext-18-session.ini,
> /usr/local/etc/php/ext-20-curl.ini,
> /usr/local/etc/php/ext-20-filter.ini,
> /usr/local/etc/php/ext-20-gd.ini,
> /usr/local/etc/php/ext-20-hash.ini,
> /usr/local/etc/php/ext-20-json.ini,
> /usr/local/etc/php/ext-20-mbstring.ini,
> /usr/local/etc/php/ext-20-mcrypt.ini,
> /usr/local/etc/php/ext-20-mysqli.ini,
> /usr/local/etc/php/ext-20-openssl.ini,
> /usr/local/etc/php/ext-20-xdebug.ini,
> /usr/local/etc/php/ext-20-xml.ini,
> /usr/local/etc/php/ext-20-zip.ini,
> /usr/local/etc/php/ext-20-zlib.ini
>
> running via the web server the info.php file gives (reformatted to look like the above):
>
> Configuration File (php.ini)
> Path /usr/local/etc
> Loaded Configuration File /usr/local/etc/php.ini
> Scan this dir for additional .ini files /usr/local/etc/php
> Additional .ini files parsed
> /usr/local/etc/php/ext-18-session.ini,
> /usr/local/etc/php/ext-20-curl.ini,
> /usr/local/etc/php/ext-20-filter.ini,
> /usr/local/etc/php/ext-20-gd.ini,
> /usr/local/etc/php/ext-20-hash.ini,
> /usr/local/etc/php/ext-20-json.ini,
> /usr/local/etc/php/ext-20-mbstring.ini,
> /usr/local/etc/php/ext-20-mcrypt.ini,
> /usr/local/etc/php/ext-20-mysqli.ini,
> /usr/local/etc/php/ext-20-openssl.ini,
> /usr/local/etc/php/ext-20-xdebug.ini,
> /usr/local/etc/php/ext-20-xml.ini,
> /usr/local/etc/php/ext-20-zip.ini,
> /usr/local/etc/php/ext-20-zlib.ini
>
> They both use the same ini file for json. I don't see any differences between them.
I found the problem. The following lines were missing in http.conf:
<FilesMatch "\.php$">
SetHandler application/x-httpd-php
</FilesMatch>
<FilesMatch "\.phps$">
SetHandler application/x-httpd-php-source
</FilesMatch>
Somehow during the installation process that file got replaced by a generic copy and those lines vanished. The way I found that was by setting up yet another test server and it worked. Then compared the various config files.
More information about the freebsd-questions
mailing list