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 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器