We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Advice needed for a large project

At my work we are moving our web services from one monolith site written in an in-house framework over to smaller service clusters, organised by function.

Each cluster will be a modular Phalcon project where each module will be a new version number.

The only problem is that we have some procedures which are shared across different clusters, and don't want to reproduce code.

Our first thought was to program these global functions in Zephir, which might not be feasible, depending upon how well Zephir works with databases.

Anyway, does anyone have any experience with doing this in Phalcon? And what would their recommendation be for sharing functionalities across sites?



98.9k

Is an option expose a common webservice to consume that functionality? Is the problem distrubuting the code across the machines? Why it can't be copied in every app?

At the moment, I'm using the common service solution (or rather, I'm still programming it),but our sysadmin is not too happy with this unnecessary extra network traffic for internal requests. We are a quite popular European weather website, and our traffic is growing exponentiall, unlike our hardware budget. Because of this we are also in a state of near constant optimisation.

My preference would be to put the common functions into Zephir (I have a question open on the Zephir forum about database access, is it possible, and how). In fact.

As for copying it into every app, that is an update nightmare ;-)

If you don't want to consume it as an API, have you thought about using composer to manage that dependency in every project? You can use private repos in composer and this seems to be exactly what you are looking for so you don't copy/paste the code from project to project.

https://getcomposer.org/doc/05-repositories.md#hosting-your-own

Again the problem with that is with updating. If I change a common function, I have to update every service cluster.

That said, composer is a very interesting option that we hadn't even considered.

Again the problem with that is with updating. If I change a common function, I have to update every service cluster.

That said, composer is a very interesting option that we hadn't even considered.

You will face the same issues if you want to put it into zephir :(

We have a very similar issue as you. We deal with ag/weather data so between our API's we share a lot of functions and classes.

Orchestration solutions like docker make updating much easier.



98.9k
Accepted
answer

My preference would be to put the common functions into Zephir (I have a question open on the Zephir forum about database access, is it possible, and how). In fact.

Phalcon 2 uses PDO to access databases, I don't think you'll have problems using any others database functions provided by PHP: https://github.com/phalcon/cphalcon/tree/2.0.0/phalcon/db

Also you can use:

edited Oct '14

For our project (I'm not sure exactly how much information I can give out), the Zephir solution will be the best.

We have core services that are used throughout our whole web services platform, the most obvious of these being geographical information. I want to just have this available on the web server, and not have to worry about installing it for each service cluster.

Once developed, these services will very rarely change, and we can just add them to our standard server image.

It will also be a good test for Phalcon and Zephir, because we will be talking about an average of 2 million hits per day, with our current record being around 8 million.

We already have one Phalcon site live, our mobile site (m.meteovista.co.uk is the english language version) and the site performs very well indeed.

Anyway, I'm starting to ramble now. Thanks for the advice.



98.9k

That's great, it would be great if you can add your portal to: https://builtwith.phalcon.io/

We already have one Phalcon site live, our mobile site (m.meteovista.co.uk is the english language version) and the site performs very well indeed.

Anyway, I'm starting to ramble now. Thanks for the advice.