I converted my matlab program into a .net assembly i.e a dll file. I have made a console C# application adding the dll file and called it from php. The MCR is called everytime the .exe is called. How can I make the MCR to initialize on the starting up of server and not closing everytime even if the exe is called after a certain time??And if there are any other methods to make this process fast please suggest.
Not a whole lot you can do here directly. The MCR architecture has a high startup cost; it's not great for repeatedly-called short running programs.
You can make it faster by:
But these probably won't get you super fast; almost certainly not fast enough for reasonable page load times.
To really get it fast, you may need to change your program architecture to a client/server one, where you fire up a persistent server process that has your MCR code running in it, and it serves requests to your PHP clients. You'll need to do additional coding to make sure the requests are serviced in a "clean" context.
You could also load the MCR dll into your web server so it persists across the server lifetime. This would be a simpler setup, but you might be limited by the single-threaded Matlab session, and would have to deal with getting a clean starting point for each request.
The MathWorks solution to this is the new Matlab Production Server, which can load up compiled MCR code in to a worker pool and service client M-code requests from warmed-up preloaded Matlab worker instances. It addresses exactly this problem with MCR apps. The point of this or a DIY client/server approach is to "spin up" your MCR code in Matlab sessions before the client requests happen, so your clients never see the high MCR startup costs.
EDIT: There's a whole MathWorks guide on deploying MCR components to the web, the MATLAB Application Deployment Web Example Guide, that doesn't use just the Matlab Production Server. Looks like they mostly say to go client/server, but you can also load up your MCR component directly in the web server for low load levels.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With