I'm in the process of creating af CAS tool that uses Sage as the underlying math engine. It's a web application, so most of the code is HTML/Javascript and some underlying PHP from which I'd like to use Sage. Currently I've resorted to the -c
command line option and executing it through PHP with exec()
.
This approach is extremely slow (takes several seconds and CPU load is fairly high). This is - as far as I'm aware - a result of Sage having to load all its libraries each time it's run.
Is there any way I can optimize this approach? I would prefer an approach similar to the -c
option where I can just send a command and read the printed result.
I have no issues writing a wrapper in C (or Python if neccessary), nor working with sockets (if any are available) provided it can be done as simple as the -c
option (the WebSocket messages seen in Sage Cell seems too much trouble to do manually).
What I need to know is mostly whether or not it's even possible, if so then where to start otherwise I'd like to know if there are any alternative approaches?
Why not use Sage Cell/Cloud?
Several reasons:
- I don't have complete control of the UI, so I can't actually embed a Sage Cell.
- The CAS tool is part of a much larger system with other services sharing resources.
- Both are a bit overkill for the job since they include a UI and webserver - I just need to send the command and read the response.