doujiao7483 2009-02-06 16:57 采纳率: 0%
浏览 67
已采纳

有没有一种从PHP脚本调用CGI脚本的好方法?

I saw that there is a virtual() function in PHP that will call a CGI script, but is that the best way? Can I pass any parameters to that scripts as well?

I saw some examples using file_get_contents() or include() and passing in the URL of a CGI script, but that feels like a hack.

  • 写回答

2条回答 默认 最新

  • dongyi1111 2009-02-06 17:32
    关注

    Use exec() if you can call it locally. If it needs to be invoked as a CGI (as in the script is designed to only work within a CGI environment), then you'll need to call it via include() or file_get_contents(). virtual() will flush your buffers and append the output of the sub-request.

    You can pass parameters through include(), file_get_contents(), and virtual() as GET parameters:

    http://localhost/cgi-bin/foo?param1=val1&param2=val2
    

    If possible, go the exec() route. Using the other methods may require a config change.

    When using exec(), you'll need to pass the arguments like you would for any CLI program.

    foo val1 val2
    foo param1=val1 param2=val2
    

    How you pass the parameters in will depend on how you want to parse them out later in the other program/script. They'll show up in the called program like they would if you called it from the command line.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写
  • ¥20 Qcustomplot缩小曲线形状问题
  • ¥15 企业资源规划ERP沙盘模拟
  • ¥15 树莓派控制机械臂传输命令报错,显示摄像头不存在
  • ¥15 前端echarts坐标轴问题
  • ¥15 ad5933的I2C
  • ¥15 请问RTX4060的笔记本电脑可以训练yolov5模型吗?
  • ¥15 数学建模求思路及代码
  • ¥50 silvaco GaN HEMT有栅极场板的击穿电压仿真问题