2

I am working on an Encryption Project and have used PyCrypto module in Python for all the Cryptographic algorithm.

When I connect PHP with MongoDB, at the user sign up I need to link each user with a specific public and private key, the code for RSA Key generation is in Python and I am using PHP to store all the user information in MongoDB.

How to call Python scripts and use the output in PHP without executing the script in shell first as it is a time taking process?

Is there any cross-compiler present for both PHP and Python so that I can execute on the same compiler ?

Manuj Mittal
  • 97
  • 1
  • 2
  • 12
  • Please use the site-search before posting a question. We try to keep questions on topic and generalize individual problems. Thank you! – hakre Dec 24 '15 at 16:25

2 Answers2

2

You could use exec (which eventually runs the script in the shell)
As described in the documentation the first argument to the method will be the command you want to run and the second one will be a reference which will hold the output

Ali
  • 2,993
  • 3
  • 19
  • 42
  • as mentioned I do not want to use shell for shell execution, that is a time taking task. Is there any other way to do it like using a cross compiler ? If yes please share the links. – Manuj Mittal Dec 24 '15 at 15:59
  • Like anything that does soemthing, using exec (or for that matter inline code) is a *time taking task*. Unless you represent your metrics and requirements (quantified) so that it becomes clear what on any time taking task would be a no-go, it would be actually answerable if not exec is the solution. – hakre Dec 24 '15 at 16:20
1

There is no cross-compiler AFAIK. And for a non-toy project I would be very cautious of using something that promise to work both with PHP and Python. :)

To avoid creating a process everytime you want to run your Python script, you can implement server-client architecture using sockets to communicate between Python and PHP. Server being your crypto library in your case and client is your PHP script that queries the server.

It essentially means that your Python script is a long-running script (to avoid the cost of creating it again and again).

MartyIX
  • 27,828
  • 29
  • 136
  • 207