I have a custom codechecker in python, Also there is a bigger project running in PHP, which stores users code in MySQL database.
I am new to python, so I'm not sure how I can pass the code from PHP to Python.
Do I have to store the file to the filesystem to pass it to Python? (In that case too many files might be created, and their cleanup after execution has to be taken care)
To expand on Brad's answer, there's several options, each with pros & cons...

Pipes (ie: STDIN/STDOUT): proc_open()
Shared memory: shmop_open()
AF_UNIX family sockets: socket_bind()

You'll probably want to use the first option but read up on the others before making a commitment.
Passing code to python from PHP