简体   繁体   中英

How Can I embed C or C++ compiler in a Php project

I am working on a Laravel project Where I want to have a textarea and a execute button . The textarea will be used to write C or C++ code and the button will show the output in any place of my website. Is that even possible I don't know may be what I am thinking may be stupid but if its possible I want some suggestion from the experts. Thanks in Advance

First of all it is possible. Text area will not work and I would suggest to use ace editor.

Secondly, PHP do have in-built functions like system() , exec() and shell_exec() and find the details on http://php.net/manual/en/ref.exec.php .

Also, if you are on linux then you can use the g++ compiler to compile the code and make the .out object and then run that object using shell_exec() and return the output in the browser and echo it.

But you have to take care of the security issues and anyone can hack your system. Also you have to take care of the resources like CPU and Memory being used by a program.

Hope it helps.

Hei Bashar the Coder ,

Obviously, you can make your own C, C++, java, python and also others onilne compiler... First see, Kinshuk Lahiri and if you are'nt a boss or security specilist or have a good knowledge on security, please avoid this..

By the way you can make a compiler from this source codes of github.. https://github.com/bhargavgolla/Online-Compiler

Or https://github.com/apanimesh061/OnlineCompiler

And I think, you can face problems of setup of that pages.. Specilly for C, C++ and for java you've to set your path variable in the system advance option if you are using Windows and if LINUX then follow their instructions....

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM