RESTful APIs: Dealing with Oracle data through PHP

RESTful APIs: Dealing with Oracle data through PHPJosé Antonio PérezBlockedUnblockFollowFollowingApr 10Photo by Thomas Jensen on UnsplashLately, I have been involved in a process of migration and refactorization of some legacy code to a more up to date platform and architecture.

One of the goals of the project was to make a clear separation between the backend and the frontend components of the application.

All of the backend had to be written as RESTful services using PHP as the chosen language, so we took our time to evaluate what could be the most appropriate set of tools an libraries to do our tasks.

After some initial tests and several proofs of concept we decided to use the SLIM PHP micro framework because it is extremely lightweight and it fits perfectly into any API oriented project.

In our working scenario, the API had to recover data from a variety of databases, and one of them was Oracle.

Our intention was to create a set of microservices in a cloud oriented environment.

In order to create the Oracle middleware, we decided to use the following ecosystem: Apache, PHP7 with OCI extensions and finally the PDO wrapper all over the rest of libraries and drivers.

In order to ease the creation and setup of all the necessary components, we chose to create a base Docker image that would be used as an initial setup for whatever future microservice who had to connect to any of the different Oracle databases.

We consider that we spent too much time looking for information and dealing with some issues while trying to create this base Docker image, so we decided to share our final setup since it can be useful to anyone interested in a similar setup, i.


the creation of a PHP based RESTful API getting data from an Oracle database.

Should you be interested in, you can have a look to the base-pdo-oci GitHub repository.

The GitHub repository contains all the necessary elements including the Oracle Instant Client files.

Although those files are property of Oracle, the license allows their distribution.

Anyway, if you prefer you can download the latest version of the drivers from the Oracle site.

There are some comments about our image:It is built on top of Ubuntu.

We know it is much more common to use lightweight base images such as Alpine, but in our case apart from the docker framework we have many physical machines mostly running LTS versions from Ubuntu server.

We chose Ubuntu as our starting point in order to maximize the possibility of reusing this setup.

PHP has been chosen as the implementation language.

Some people show criticism about PHP not being as efficient as other languages, but our experience with the language in some previous medium size projects has been very positive so far.

Apart from that, there has been significant improvements in performance since the publication of PHP 7.

We are considering to do some performance comparisons between PHP vs.

GoLang, but that will be the topic of another article.

We finally decided to include just the PDO_OCI extension and not to include the OCI8 one.

The reason for this decision is that all the PHP code written by us over the last years was done using the PDO syntax and functions.

Since the results have been very positive so far, we want to keep doing things this way.

At the end of the base image, a minimalistic PHP script with a call to the phpinfo() function is created in order to verify the proper behavior of the current setup.

.. More details

Leave a Reply