dongwupei7803 2014-12-06 20:33
浏览 36

在heroku上的Flask应用程序中运行PHP脚本

I know, I know, sounds very bizarre.

I have a flask application on heroku which is running plenty fine. I must have one page which runs a PHP script, which will have little to nothing to do with my flask back end. It connects to an external database and renders a few rows on the page. Eg,

<?php
  mysql_connect($hostname, $username, $password) or DIE ("connection failed");
  mysql_select_db($dbname);
  $id = REQUEST["id"];
  $query = "select * from table1"
  $result = mysql_query($query) or die(mysql_error());
  $row = mysql_fetch_array($result);
?>
// leaving out for brevity
<div class="container">
  <?php
    echo "$row['name']<br/>"
  ?>
</div>

However, if possible, I would rather not make a FULL new application to run a one to three PHP scripts. All that is important is that the script in the PHP page runs. The db is an external mysql database

Is it possible to run this along side a flask application? If so, how?

  • 写回答

1条回答 默认 最新

  • doujia6433 2014-12-06 20:41
    关注

    First of all you need to make sure that your Heroku app runs with PHP installed; probably it does not.

    You can probably get this using a custom build pack that ships with both PHP and Python.

    Once you have PHP you can run the scripts invoking PHP's interpreter from Python.

    php_output = subprocess.check_output(["php", "script.php"])

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#网络安全#的问题:求ensp的网络安全,不要步骤要完成版文件
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥20 使用Photon PUN2解决游戏得分同步的问题
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM