PHP site scheduling Java execution?
I'm trying to get started on combining my (slightly limited) PHP experien开发者_开发百科ce with my (better) Java experience, in a project where I need to allow uploads of Java source files to the server, which the server then executes Javac on to compile it.
Then, at a set time (e.g. specified on upload) I need to run that once on the server, which will generate some database info for the PHP site to display.
To describe my current programming abilities- I have made many desktop Java programs, and am confident in 'pure' Java, but so far have only undertaken a couple of PHP projects (including using the CodeIgniter framework).
My motivation for using PHP as the frontend is because I know it is very fast, lightweight and I will be able to display the results I need very easily with it (simple DB readout). Ideally, the technology used should be able to be developed on a localhost (e.g. WAMP, Tomcat etc..)
Is there any advice which you could give on what technology I should consider to use to bridge this gap, and what resources could help in using that technology? I have looked at a few, but have struggled to find documentation helping in achieving what I need.
There's a large number of ways to approach this and you didn't provide enough details to narrow down to just one way, so I'll propose a few... Compiling the java source will probably take too long for a normal web request, so my recommendation would be to have the PHP script which accepts the java source files run a background command which compiles the source files and logs it's progress to a database or log file. This way, you can redirect the user to a page that says, "Please wait, your source is being compiled" and use Ajax to check in every few seconds to see the updated progress. If this is the route you want to go check out the PHP exec command.
It might be more beneficial for PHP to simply create an ID in a database for each uploaded file and call move_uploaded_file to move the source files to an "incoming" directory. From there, a cron job that runs every so often can scan the incoming directory or the database for source files, compile them, and update the database when done.
In either of these cases the program which does the compiling could be written in any language, even Java, if you prefer.
精彩评论