Run PHP codes on the fly using phpExec

phpExec is a small tool I did to execute php snippets on the fly. Basically it is like jsfiddle for php which should be hosted by yourself.

phpExec is a simple script written in php which provides an in-browser editor to write and run php codes. the only requirement would be having php binaries on your machine. you can either use the built in php server functionality shipped with phpExec or place the copy in your web server folder and access it locally.

with phpExec you do not have any limitation on which functions that you can use, so you can even kill your machine with your code if you wish to.

Up and running phpExec:

To get started with phpExec simply download the repository in github and run composer install within the folder to download the required dependencies.

Once you have the folder downloaded you can place it on your local webserver and go to phpExec editor without any additional configuration.

While that would be the fastest way to up and run phpExec, you also could use the phpexec command line utility to run the app on php built-in server.

Running phpexec on the built-in web server would let you to modify the php.ini variables easily by editing the file shipped in the root folder of the project.

to start try running:

to run phpexec on the built in server simply use the command

This will run phpExec on localhost:8000 by default. as an additional argument you can pass host and port number to the serve command.

you can also use includes in phpExec. running phpexec make:include command will create a folder and a file within the root directory named as includes/ & includes.php.

once this is done you can add any custom class or php files in the includes folder and reference them in the includes.php .

Also remember symfony var_dumper is already loaded with the page. you can use the dump function anytime within your snippets.

phpexec official page | phpexec github page

 

 

Detect MIME type and buffer it to browser using PHP

The following piece of code handles detection of mime type, file size and existence of the file for you. I always use this piece for buffering files into browser of my users.

All you have to do is to change the variable of $filelocation with your own variable which contains the full address of your local file.

Hope it helps some of you out there.