PHP to Node conversion

IMO if you are really wanting to do something this big it would be a good idea to start almost fresh on a more recent Wappler version 3.9.7 is very old now and while I respect this may work for you there has been a lot of improvements since then.

You may find there is even easier ways to do things now in certain areas for example global database connections (think that was wappler 4 could be wrong) this is just one of many examples not to mention things like the NodeJs date time updates that made things more universal.

As someone who was a staunch PHP advocate and having switched to Node we won’t be going back! Too many benefits to Node. One of the mightiest for us is Scheduled Events on the server side! There are dozens of benefits @Antony. Yes the workload in making the transition for large Projects can be lengthy but the reward is worth it when you are done. Bite the bullet. You can leave your PHP version up while you work on version II of your app in the background, all the time making vast improvements as you work through what you need to do. And update Wappler at the same time!! Man you are missing out on so much (just don’t update your stable Project, you have the choice in the Project Updater). Again we halted for a long time on 3.9.7 (definitely one of the most stable releases to date), BUT you need to move on or you’ll just get left in the dirt as Wappler accelerates. Hard to move on from what you know and trust but hey man, that is life! You have to get to the next corner to look around it and see whats coming.

Antony, can you define what you consider huge, i.e. number of Server actions/ pages. It is a very subjective term.

Hey everyone, thank you for the love I feel in your posts! :blue_heart:

This is all coming to mind as today I will begin the task of upgrading from 3.9.7 to 5.9.7, and PHP from 7.4 to 8.2, so my development focus shifts from features to framework upgrade.

@Hyperbytes, I have around 400 server actions… many are simple crud actions, but some have complex maths algorithms. There are also S3 actions and a bit of custom PHP.

I’m using cron in PHP to schedule actions at the moment…

I’m wondering about the technical possibilities of having half the back end in PHP and half in Node for a while too.

The front end of my app is a single index file with a cascade of around 40 PHP include files it loads at start-up. It works like a dream! So this would need to become partials I guess… but right now I know nothing more detailed than the word “partials”! Which makes me realise I will need to know more about Node, but I’m not quite sure what it is I will need to know!

I also have quite a lot of app flows and data stores on the front end…

I also want to plan the development of a mobile app with local data storage for when the user is off-line, and I’m sure the switch to node and the mobile app journey will effect each other in ways I currently don’t understand.

There are so many thoughts in my head about how to approach this, and I want to leave an easily searched legacy of this journey for others to follow.

At the moment I’m in an information gathering phase… hence appreciating the idea of a forum category where each aspects of this journey can be discussed in technical detail so I can create a realistic timescale for the project and leave a documentation trail for all those who follow to use. Using my experiences for the benefit of others is a massive part of what I have always wanted to bring to our wonderful community!

@mark1, I’m wondering if there are monthly meet-up topics to consider from all of these questions too…

A big fat Thank You :pray: to all of you who are bringing your time and care to this topic!

Antony.

400 SAs is not that big in the grand scale of things. You could convert them over in a matter of a few hours.
You coud replace all the cron jobs to node scheduler actions,again not a huge job, it’s just a copy/paste process with the json.
All those includes would all need to be changed over manually, that would be the biggest job.
Ironically the fact that it is a single page will make things easier as there is no need to move over to a layout/ content page architecture. Lastly and <?php directives and to be changed over to node equivalents or alternatives.
I really wouldn’t advise trying to run a php/node hybrid,technically it may be possible but highly inadvisable.

1 Like

Once Wappler is updated and the site converted you may them want to look at your data structures as new features like sub tables and multi joins may be able to streamline your data management code.

1 Like

@Antony,
Having gone through the conversion before with a similarly complex site, I can assure you that it isn’t as difficult as you probably think.

Because they are JSON-based and have the same structure irrespective of server model, most of the PHP SC action files can be copied as whole folders. Then just change the file extensions. You will need to then remove the opening section of the PHP files:

<?php
require('../../../dmxConnectLib/dmxConnect.php');
$app = new \lib\App();
$app->define(<<<'JSON'

and the closing part:

JSON
);
?>

The JSON for the vast majority, if not all, of API file steps are the same between server models - the main thing to look for that might need changing is where steps refer to a file path. There is a difference with the S3 file upload step for AWS - the response of ObjectURL is Location for Node but a find/replace should sort that.
All the front-end stuff (apart from the server-side data binding which is available through NodeJS) should be agnostic, once you have got the structure sorted for Partials vs PHP Include

2 Likes

We were actually planning a server model converter for some time now that will at least convert your server actions, as those are mostly identical indeed per server model. Maybe we should put a bit more priority on it :slight_smile:

But the rest of the site like the template pages and includes will still require a manual convert.

So there won’t be any magical tool indeed but the converter might save you at least some boring copy/paste convert and give you at least some head start.

6 Likes

The biggest problem are the PHP includes, and NodeJS templates are not yet the perfect solution as they lack support for nested includes:

This means you have to re-think templates instead of copying the majority of the includes from PHP.

That was one of the things I noticed when I migrated from Laravel (a PHP framework) to Wappler NodeJS, Wappler has in inferior templating engine despite NodeJS being preferred by many advanced users

Hey @apple, so are you saying that if I have in my PHP:

index.php  - includes level1.php
level1.php - includes level2.php

So an include tree like this:

       index.php
           |
       level1.php
           |
       level2.php

Then in Node, I can’t include level2 in my level1 file as it is a template file and templates can’t include templates?

This would definitely be an issue for me… I’m not sure how many levels my includes go to in my PHP design as I’ve never had to worry about it!

And are you saying that native Node allows this but the Wappler implementation doesn’t? And if so, can I just hack something at the code level to allow it?

Is this still an issue since my app is just a single page?

Maybe I need to play around with templates in a trial node design to get my head around this!

It seems I now got confused as heck, because it seems EJS (the templating engine Wappler team chose for NodeJS) does supports includes, which are called “partials” in Wappler. So, your design could be like this:
index.ejs -> includes partial level1.ejs > includes partial level2.js

However, in that feature request topic, I wrote this:

So, you might get away with using partials, although the development experience might not be the best. It’s been a while since I touched this subject, so I don’t remember a lot of intricacies. I know for example in my user dashboard, I’m including the dashboard sidebar partial on every page, instead of just using a “user_dashboard” template as base that would automatically include everything I need

Pinging @JonL in case he has any comments to add

1 Like

How about this for a thought, PHP and Node can co-exist with the aid of an Apache or Nginx proxy server as can be seen here: NGINX as Reverse Proxy for Node or Angular application | DigitalOcean

The details on how to go about such a combination within Wappler would need to be worked out. Maybe @George or @Teodor can help out.

You could start converting a certain section of the site and gradually work through it. Maybe keep the backend as PHP?

:kiss: (keeping it simple)

Instead of using nested/sub layouts, why not create the full template page with conditional regions.

1 Like

Not much to add besides the layout FRs.

Wappler’s server routing has been lagging for quite some time. Some love would be appreciated.

I think the main problem with partials is UI picker support as the partial doesn’t have access to the data of the page it’s in.

1 Like

@Antony I had a similar issue but with Classic ASP and .NET. Its a huge application that had to be converted to NodeJS, after much research I reluctantly figured the best way was to completely start again from scratch - that was a big decision as the site had been developed since 1997 and it grew organically since then with various different bolts ons. We were also using PHP on some backend parts, migrating to PHP 7 or 8+ wasn’t possible as we had too many breaking changes - I’ll let you all imagine what all the code looked like.

I found out the following:

  • It wasn’t as big a nightmare as I was expecting, yes, there were/still are some technical issues, but there are easily worked out with work and a bit of thought.

  • The end result was very robust and future proofed for a long time, Once I started breaking open the earlier code I could see it was terrible in some places so replacing it was essential (Wappler does indeed output some great looking code)

  • We can run everything now on NodeJS and no longer have to mashup with PHP, Classic ASP, .NET etc This obviously means its much easier to update and maintain.

We have another six or seven in-house sites / applications still to do, including a very recent .NET application that I’ve decided to give the same treatment.

I’m not too sure if this will help you much but I suppose my summary would be to suggest the transition to NodeJS from PHP may not be as brutal as you imagine.

2 Likes

That’s a great point, its a bit of a bugbear of mine to have to handball my partials as they cant access the parent data, hopefully we’ll get an update to this at some point.

Thanks for that perspective @JonL… the good news for me is that PHP includes don’t seem to either, so I gave up using the data picker near the start!

Also… the data picker just isn’t designed in a way that is any benefit to a really really big design, IMHO!

@ben, I think the simple answer is that is makes life waaaaaay too complex to have it all in one file!

Thanks for the co-existing ideas @ben… I appreciate that! :tada:

Apologies @Antony for my delayed response. There are plenty of good topics in your post however the issues we experience with MeetUps is securing Wapplers to present on good topics. Is there a good solution or example or sample site/app you would like to present at a monthly MeetUp?
Thx

3 Likes