简体   繁体   中英

Executing an external python script in HTML webpage using PHP

I am new in this field and also my background in Biology.

I am working on biological databases. I have developed a database using MySQL, HTML, PHP, and Bootstrap, but, I want to add an analysis module such as algorithms written in python.

For example, I want to add a sequence search algorithm. (for example, There are already sequences in my database and when someone enters his/her sequence my database will show the similar sequences)

However, I am unable to find any suitable tutorial on how to run an external python script and show results on the webpage.

For PHP I learned about shell_exec() function but when I run the script embedded in this the result shows nothing.

Can anybody please help me in an easy way to connect my python script with PHP and show results on the HTML webpage.

I do not you are using the same server or different server, but you should use the pythong code (any other language) as the api and call it from you html code using ajax and display at your page.
you can do it in your php code using curl. 
you can try curl as follows - 

//  Initiate curl
$ch = curl_init();
// Will return the response, if false it print the response
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Set the url
curl_setopt($ch, CURLOPT_URL,$url); //url will be your python code url independent from you php project code

// Execute
$result=curl_exec($ch);
// Closing
curl_close($ch);

// Will dump a beauty json :3
var_dump(json_decode($result, true));

you can read the curl from [here][1]

you can use the response from the url in you html view to display

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