What Does PHP to Node REALLY Involve?

I’ve been loving all the banter on the “PHP is Dead” thread.

So lots of you are saying you will start your next project in node.

I’d probably do the same, but I will only ever have one project and it is massive.

So now many of you have made the shift, I’d love to know what is really involved?

@George, should I even consider a manual change if a converter of some kind is on the horizon?

@Hyperbytes, you have mentioned editing server action files to do the conversion. Was there much to do? Would you take on a project?

My app would really benefit from what node offers in the long term, and it would be great to get a big picture of the routes and efforts involved in getting there!

I love NodeJS and have created all of my latest projects using the server model. However, PHP is not dead. There are still plenty of reasons to use PHP especially when there are calculations to be made.

What I am trying to say is, leave the PHP projects as such and do your research before embarking on a NodeJS project.

2 Likes

Server actions are pretty easy, simple copy paste and remove the PHP wrapper code
so this in PHP

<?php
require('../../dmxConnectLib/dmxConnect.php');


$app = new \lib\App();

$app->define(<<<'JSON'
{
  "name": "",
  "options": {
    "comment": "sdfgsdfg"
  }
}
JSON
);
?>

becomes for NODE

{
  "name": "",
  "options": {
    "comment": "sdfgsdfg"
  }
}

i.e. ditch everything outside the curly braces

Retiring, no new projects (except for fun or wappler training purposes)

1 Like

Brian, you are much too young to retire.

1 Like

But luckily too wealthy to want to work! Love coding, hate customers so from now on, other than supporting existing customers, I only code for fun

5 Likes

For info, pages themselves are pretty much identical (unless you have embeded PHP in them) other than the security provider works differently and of course PHP includes would need to be changed to node partials. Of course a simple copy/ paste or rename of the pages will not give you the benefit of templates and partials but it will work with a few tweaks
Generally, with NODE, the head part of the page would be in the layout and the body in the view

1 Like

@George, is this a complete list of what you would need to change? Or if not, would you be able to give us a complete list?

Perhaps a better approach would be for you to say what PHP specific code you use and how extensively for example

  • Security Provider
  • PHP Includes (can be a big one if used extensively)
  • Embedded PHP in browser pages
  • PHP in SAs
    (these are the main areas)

so he can judge the extent of your needs otherwise you are asking how long a piece of string is

1 Like

In my experience of transferring one of my projects (not one of my most complex ones but I could have easily used the same process for any size project) from PHP to Node:

  • Copy/Paste a lot!
  • Set up globals you have in your project in the new Node project. Make sure things like the security provider have the same name. If using argon, you will need to use @jonl’s extension and then, if successful, pull some ‘login information’ from the db that you then use for Security Provider.
  • I created a copy of the SC API files and renamed each of the extensions to .json, removed the start/end PHP code, using a code editor, from each (leaving just the JSON in the file). Then copied them into the new node API folder
  • Be aware that some SC actions will need changing, particularly where file paths are involved (file uploads, file saving, image actions). In many cases it is a quick change of path to a suitable folder in your new project.
  • I created a layout page and copied the non-route html from my main PHP page, trying to ignore the Wappler generated head lines as they will be generated in your new project when creating the pages. If using components on a layout/content page (such as autocomplete/tooltips/calendar/modal/collapse/dropzone/summernote/form validation etc.) you might need to add an element to a page and remove (just to ensure that the relevant resources are linked by Wappler)
  • I create a new content page for each of my route pages, copying the HTML from one to another (open old page in text/code editor to allow copy directly to Wappler without having to keep switching projects)
  • Each page needs some adjustments:
  1. SC links will be to a different location (find/replace solves the vast majority of this as it should be replacing the path to the file if you named the files the same as previously. Then use find/replace to remove the .php extensions
  2. Consider any usage of includes or php tags - these will not work. If you need server-side data you can include a suitable SC in the page settings and re-reference as appropriate.
  3. paths to resources (images/files) may have changed so need checking. Usually a find/replace sorts this.

This is not exhaustive, it was a little while ago I did mine so may well have missed a couple of bits but I think I’ve got the bulk of it.

I had some pretty long, complex SC actions and the vast majority needed no major changes. DB queries/inserts/updates, conditions, repeats etc. worked perfectly fine. It was mainly where I was handling files that needed changes after a copy/paste of the JSON.

3 Likes

@bpj, that is an amazingly detailed response, thank you sooo much! That gives me the confidence to tackle the project knowing how much I’d need to change.

1 Like

Does anyone have experience of using node with MySQL?

I have an existing client database and quite a lot of stores procedures (!) that I really don’t want to mess around with…

Dont know how it handles the stored procedures… but im sure it should work… best is to make a copy of it…

my scenario is…
I have wamp installed as a local server… as im using localhost and phpmyadim as I still have loads of php projects… just because they are “established” clients with shared hosting on php…

So when i created my Nodeproject I opted to do a direct connection to my database… eg via localhost…
So all the data still remained on phpmyadmin as per normal… so i have the best of both…

So far its been quite a journey… as Ben has explained… its quite the job… as im doing 350+ sever connect pages/ api’s … not to mention the .php pages 500+ (… the globals… the routes… copy paste… copy paste… its madness… but i can tell you one thing… Node is great if your server supports it… faster … way faster… and once you have the basic pages setup its a breeze… i still have loads to learn as some of the functions and queries work different… but worth it… i would not disregard my php projects… but if i could choose is to move all my new clients to node…

So to get back tot he point… yes im using mysql… and using phpmyadmin…
So make a copy of your database… setup a node project… and just link it directly…

2 Likes

That is amazing feedback @Mozzi, thank you so much! :slightly_smiling_face:

ddd

and then i still do all the changes via phpmyadmin. as explained i do this because of all the other projects pending in php… but the database manager tool directly in wappler is super cool… on new projects.

1 Like