控制在共享托管中使用 Twitter 流 api 的 php 脚本

发布于 2025-01-04 19:31:57 字数 357 浏览 1 评论 0原文

我正在开始实现一些代码来使用 twitter“streaming api”。我一直在阅读并了解到这是一种一次性连接,保持活动状态,当出现一些更新(或类似的东西)时由 Twitter 提供,对吗?

那么,有谁知道我应该如何控制共享托管环境中的 php 脚本,以便我可以按照自己的意愿启动和停止使用此 api 监控推文?

我还没有找到(然而)有关如何使用 php 和共享托管执行此操作的信息,并且不想:

1)终止共享服务器并让我的托管提供商禁用我的帐户

2)超出连接限制到stream.twitter.com并获取我的ACC。禁止

提前非常感谢,

I'm beginning in the process to implement some code to use twitter "streaming api". I've been reading and learned that it is a one-time connection, kept alive, that is fed by twitter when some updates appear (or something like that), right?

Well, does anyone know how should I do to control a php script in a shared hosting environment so I can start and stop -at my own will- monitoring tweets with this api?

I haven't found (yet) info about how to do this with php and shared hosting, and don't want to:

1) kill the shared server and make my hosting provider disable my account

2) exceed the connection limits to stream.twitter.com and get my acc. banned

Thanks a lot in advance,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小帐篷 2025-01-11 19:31:57

我延迟回答这个问题,我认为您可能已经放弃或自己解决了。

我对这个问题不是 100% 确定,但我想你问的是如何停止和启动连接到 Twitter 的脚本。我简单地使用过流 api,发现它非常有用。一般来说,共享托管很烦人,因为您被允许执行的操作受到限制,因此您不会使用超出公平份额的资源。

您不太可能制作一个脚本并通过网络浏览器使用它,因为脚本通常会在一分钟左右后被杀死。因此,运行该脚本的最佳方法可能是通过 cron 脚本使用它。让 cron 运行“php -f /path/to/script.php”或“wget http://example.com /script.php”。你必须让 cron 每分钟或不管多久运行一次。我相信,如果您第二次重新连接到流 api,它会立即断开第一个实例的连接。

至于控制它,我会制作第二个脚本,它只有一个开/关开关。它只会创建一个文件或删除它,原始脚本将检查它是否存在。如果文件不存在,它只会连接到 Twitter。

至于 Twitter 的限制,我相信只要您不尝试同时跟踪太多(5000)个用户或太多(400?)个关键字,您就应该是安全的。

Rather a delay on my answering this and I assume you've probably given up or figured it out yourself.

I wasn't 100% sure on the question but I think what you were asking how you would stop and start a script that connects to twitter. I've briefly used the streaming api and found it very useful. Generally shared hosting is annoying as you are limited in what you are allowed to do so that you don't use more than your fair share of resources.

It's unlikely that you could get away with making a script and using it via your webbrowser as scripts will often be killed off after a minute or so. So maybe the best way to run the script is to use it via a cron script. Either make cron run "php -f /path/to/script.php" or "wget http://example.com/script.php". You'd have to have cron run this every minute or however often. I believe that if you reconnect to the streaming api a second time it immediately disconnects the first instance.

As for controlling it, I would make a second script that simply has an on/off switch. It would simply create a file or delete it and the original script would check for it's presence. It'd only connect to twitter if the file didn't exist.

As for twitter limits, I believe that you should be safe as long as you don't try to track too many (5000) users or too many (400?) keywords at once.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文