将 PHP 脚本使用统计信息发送到外部脚本的最佳方式

发布于 2024-08-03 08:15:02 字数 378 浏览 5 评论 0原文

我正在用 PHP 编写一个应用程序,我计划出售该应用程序的副本。如果您需要知道,它用于允许用户使用过期的下载链接下载文件。

我想知道我出售的应用程序何时生成下载。

向我的服务器上的 php 应用程序发送通知的最佳方法是什么,它只是告诉它“嘿,你的一个脚本已经做了一些事情”,以及记录“数量”的最佳方法是什么?命中”我的服务器具有这种性质?数据库记录,还是平面文本文件?

我问这个问题是因为我想在我的主页上显示下载总数的运行计数,有点像:

“到目前为止已负责 X 次下载!”

纯 PHP 解决方案是一个想法,但我想 ajax 调用也可以。越简单越好,因为我真正做的只是一个简单的 $var++,只是规模更大,对吗?

有人愿意为我指出正确的方向吗?

I'm writing an application in PHP which I plan to sell copies of. If you need to know, it's used to allow users to download files using expiring download links.

I would like to know whenever one of my sold applications generates a download.

What would be the best way to send a notice to my php application on my server, which simply tells it "Hey, one of your scripts has done something", and what would be the best way to keep a count of the number of "hits" my server gets of this nature? A database record, or a flat text file?

I ask because I want to display a running count of the total number of downloads on my homepage, sort of like:

"Responsible for X downloads so far!"

A pure PHP solution is idea, but I suppose an ajax call would be OK too. The simpler the better, since all I am really doing is a simple $var++, only on a larger scale, right?

Anyone care to point me in the right direction?

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

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

发布评论

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

评论(2

夜空下最亮的亮点 2024-08-10 08:15:02

无论是通过 javascript 还是 php,您都需要在服务器上设置一个其他脚本可以调用的 url。然后,该 URL 应指向一个递增计数器的脚本。我会在数据库中放入一个数字并递增它,或者如果您想更详细,您可以轻松地按月份/客户等细分它。

如果您从 PHP 调用 URL,请注意确保URL 不会阻止执行 - 即:如果您的网站出现故障,您出售的脚本不会等待服务器响应。您可以通过多种方式解决这个问题 - 我会通过注册关闭功能来实现。

没有这个问题的替代方案是使用 javascript 加载 url,或者作为图像加载(但它们都可能不太准确) - 我自己会使用图像,因为您会获得稍微更好的浏览器支持。

另外,请记住,除非您使用 Zend Guard 之类的工具编译代码,否则任何人都可以删除远程调用并阻止计数器递增!

Whether by javascript or php, you need to set a url up on your server that other scripts can call. That URL should then point to a script that increments a counter. I'd put a number in a database and increment it, or if you wanted to be more detailed, you could easily break this down by month/client etc.

If you go with calling the URL from PHP, take care to ensure that the URL doesn't block the execution - ie: if your site goes down, the script you sell doesn't sit waiting for your server to respond. You can work around this in various ways - I'd do it by registering a shutdown function.

Alternatives that don't have this problem are loading the url with javascript, or as an image (but they will both likely be slightly less accurate) - I would go with image myself, as you'll get marginally better browser support.

Also, remember that unless you compile the code with something like Zend Guard, anyone can remove the remote call and prevent your counter incrementing!

尽揽少女心 2024-08-10 08:15:02

是的,可调用的 url 就是你的东西。 SOAP 可能是解决这个问题最简单的方法。

http://php.net/soap

Benlumley 对于这个解决方案有很多有效的观点。

此外,如果您想将计算转移到用户浏览器(进行 Web 服务调用可能会惹恼购买您的应用程序的人、带宽/CPU 成本),那么 AJAX 可能是更好的解决方案。

Yeah something url callable is what you what. SOAP is probably the easiest way to go about this.

http://php.net/soap

Benlumley has a lot of valid points regarding this solution.

Also if you want to offset computation to the users browser(making web-service calls might annoy the people who buy your app, bandwidth/CPU cost) then AJAX might be a better solution.

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