doubomudichen0832 2014-11-06 17:54
浏览 89
已采纳

PHP WebSocket服务器

I use Phirehose to get a live and continuous stream of the Twitter UserStream API. So far I have been able to execute php -S localhost:8000 index.php and it work fire up and work fine. Now I want to use the data from the CLI script in Laravel.

1) How can I stream the Phirehose data to Laravel?

2) How can I get this script to stay active in the background of a non-GUI droplet @ DigitalOcean?

  • 写回答

1条回答 默认 最新

  • doushua7737 2014-11-07 20:38
    关注

    In your Phirehose script, write each tweet to a database. In your Laravel application (which I am assuming is being accessed by users, from their browsers?), query that database. The database need not be as heavy as MySQL, it could instead be memcache, redis or one of the NoSQL options.

    For getting a Phirehose script to run in the background I would login over ssh and do this:

    nohup php myscript.php 2>&1 &
    

    (This assumes you have installed the php-cli package for your distro.)

    The nohup part means you can logout and it will keep running. The 2>&1 means both stdout and stderr messages will be written to nohup.out. The & at the end is what puts it into the background.

    (In fact I do something a bit more complicated: I have my Phirehose script write to a keep-alive file every 10 seconds. I then have another PHP script that is started on 1-minute cron, that will check that keep-alive file is being updated and, if not, it will start the phirehose script running.)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 目标计数模型训练过程中的问题
  • ¥100 Acess连接SQL 数据库后 不能用中文筛选
  • ¥15 用友U9Cloud的webapi
  • ¥20 电脑拓展屏桌面被莫名遮挡
  • ¥20 ensp,用局域网解决
  • ¥15 Python语言实验
  • ¥15 我每周要在投影仪优酷上自动连续播放112场电影,我每一周遥控操作一次投影仪,并使得电影永远不重复播放,请问怎样操作好呢?有那么多电影看吗?
  • ¥20 电脑重启停留在grub界面,引导出错需修复
  • ¥15 matlab透明图叠加
  • ¥50 基于stm32l4系列 使用blunrg-ms的ble gatt 创建 hid 服务失败