execute php script in sandbox or with restricted params?

I need to test a php script's output. It's possible this script will consume too many resources, and I need to check it's output so that it matches a particular format. What's the best way for me to use php to test this script given that I only want this particular script to run with specific restrictions? Using exec, shell_output? But if so, how do I restrict it's memory usage, execution_time etc.?

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum