0

I have a web application written in laravel 8 and hosted on an EC2 instance running Amazon Linux 2. The application pulls in an atom feed. Previously, it worked fine. However, after some composer dependency issues (which i thought were resolved), the atom feed no longer works. Now, the following code blocks returns a Call to undefined function App\Http\Controllers\simplexml_load_string() error:

    $fileContents = file_get_contents($url_map[$feed]);


    $fileContents = str_replace(array("\n", "\r", "\t"), '', $fileContents);
    $fileContents = trim(str_replace('"', "'", $fileContents));
    $fileContents = str_replace('<p>', "", $fileContents);
    $fileContents = str_replace('</p>', "", $fileContents);

    $simpleXml = simplexml_load_string($fileContents);

Here's what I have already tried to resolve the issue: I ran the following command to check if the simplexml extension is installed: php -m | grep simplexml. It returned nothing, so my first action was to attempt to install the extension with sudo yum install php-simplexml.

However, received the following response, which suggests that the package is installed:

Package php-xml-8.2.3-1.amzn2.x86_64 already installed and latest version
Nothing to do

My next move was to open my /etc/php.ini file and look for a commented out extension=php_simplexml.dll. However, it was nowhere in the file. I even tried to add it and restart Apache, but no luck there.

I'm running out of ideas. Does anyone have any suggestions or insight in resolving this?

Bad Programmer
  • 893
  • 1
  • 13
  • 27

1 Answers1

0

Here's how I managed to resolved the situation:

Since I am using Amazon Linux extras, I figured that the version of simpleXML that I was rocking may have been janky. I was under this assumption because I also noticed that I had issues getting the php-json package installed correctly. When I tried to install it, I saw that it was listed under the "php8.1" topic, but nothing for my current version (php8.2).

I removed that packages and reinstalled PHP, and then each package I needed. Low and behold, it appears to work now.

sudo yum remove php-json sudo yum install php php-common sudo yum install php php-cgi .... {cli, fpm, mysqlnd, pdo, mbstring,pear, xml, json, bcmath, curl}

I did update the php.ini file to include extension=php_simplexml.dll.

After that I restarted Apache and PHP FastCGI Process Manager.

Now the atom feeds are loading properly, and I am regression testing the application to see if I need to install any additional packages, or is something else broke as the result of this. But hey, simplexml_load_string() works now, so tentative win?

Bad Programmer
  • 893
  • 1
  • 13
  • 27