为 iPhone 应用程序实现 RESTful Web API 的最便宜方法(平台/语言)?

发布于 2024-09-24 09:35:28 字数 932 浏览 1 评论 0原文

我正在开发一个 iPhone 应用程序,并希望创建某种 RESTful API,以便该应用程序的不同用户可以共享信息/数据。创建一个社区。

假设我的应用程序是某种游戏,我希望用户能够在全球排行榜上发布他们的高分,并维护朋友列表并查看他们的分数。我的应用程序与此不同,但它显示了我需要实现的集体信息访问类型。

我实现这一点的方法是设置一个 PHP 和 MySQL 服务器,并使用一个 php 脚本与数据库交互,并通过接受 GET 请求并返回 JSON 字符串来调解数据库与 iPhone 上每个用户之间的请求。

这是一个好方法吗?在我看来,与编译语言相比,使用 PHP 是一种缓慢的实现方式。但我可能错了。我正在努力降低我的托管费用,因为我计划免费发布该应用程序。我确实认识到,在 CPU 周期和 RAM 使用方面表现更好的实现(例如,用 C# 编写的代码?)可能需要比 LAMP 服务器更昂贵的托管解决方案,因此实际上最终可能会更昂贵/要求。

我还希望我的实现能够在很多人开始使用该应用程序的罕见情况下进行扩展。使用量是否会使性能/成本比率转向不同的实施?也就是说,如果我每天有 1k 请求,那么使用 PHP+MySQL 可能会更便宜,但是每天 1M 请求可能会使用其他东西更便宜?

总而言之,您将如何实现一个(相当简单的)远程数据库,该数据库可以使用 HTTP(S) 进行远程访问,以最大限度地减少托管费用?什么样的托管解决方案以及什么样的平台/语言?

更新:根据Karl的建议,我尝试了:Ruby(语言)+ Sinatra(框架)+ Heroku(应用程序托管)+ Amazon S3(静态文件托管)。对于任何读到这篇文章的人来说,如果他们可能和我有同样的困境,这个设置是惊人的:毫不费力地可扩展(到“无限”),价格实惠,易于使用。谢谢卡尔!

还不能评论数据库细节,因为我还没有实现它,尽管对于我的简单查询需求,CouchDB 和 MongoDB 似乎是不错的选择,并且它们与 Heroku 集成。

I am developing an iPhone app and would like to create some sort of RESTful API so different users of the app can share information/data. To create a community of sorts.

Say my app is some sort of game, and I want the user to be able to post their highscore on a global leaderboard as well as maintain a list of friends and see their scores. My app is nothing like this but it shows the kind of collective information access I need to implement.

The way I could implement this is to set up a PHP and MySQL server and have a php script that interacts with the database and mediates the requests between the DB and each user on the iPhone, by taking a GET request and returning a JSON string.

Is this a good way to do it? Seems to me like using PHP is a slow way to implement this as opposed to say a compiled language. I could be very wrong though. I am trying to keep my hosting bills down because I plan to release the app for free. I do recognise that an implementation that performs better in terms of CPU cycles and RAM usage (e.g. something compiled written in say C#?) might require more expensive hosting solutions than say a LAMP server so might actually end up being more expensive in terms of $/request.

I also want my implementation to be scalable in the rare case that a lot of people start using the app. Does the usage volume shift the performance/$ ratio towards a different implementation? I.e. if I have 1k request/day it might be cheaper to use PHP+MySQL, but 1M requests/day might make using something else cheaper?

To summarise, how would you implement a (fairly simple) remote database that would be accessed remotely using HTTP(S) in order to minimise hosting bills? What kind of hosting solution and what kind of platform/language?

UPDATE: per Karl's suggestion I tried: Ruby (language) + Sinatra (framework) + Heroku (app hosting) + Amazon S3 (static file hosting). To anyone reading this who might have the same dilemma I had, this setup is amazing: effortlessly scalable (to "infinity"), affordable, easy to use. Thanks Karl!

Can't comment on DB specifics yet because I haven't implemented that yet although for my simple query requirements, CouchDB and MongoDB seem like good choices and they are integrated with Heroku.

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

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

发布评论

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

评论(4

云仙小弟 2024-10-01 09:35:28

您是否考虑过使用 Sinatra 并将其托管在 [Heroku] 上?这正是 Sinatra 所擅长的(REST 服务)。使用 Heroku 进行托管可能是免费的,具体取决于您需要存储的数据量。只需将所有支持文件(图像、javascript、css)保留在 S3 上即可。您很快就会在云端飞翔。

这可能不符合您的 PHP 需求,但说实话,没有比 Sinatra 更容易的了。

Have you considered using Sinatra and hosting it on [Heroku]? This is exactly what Sinatra excels at (REST services). And hosting with Heroku may be free, depending on the amount of data you need to store. Just keep all your supporting files (images, javascript, css) on S3. You'll be in the cloud and flying in no time.

This may not fit with your PHP desires, but honestly, it doesn't get any easier than Sinatra.

妄断弥空 2024-10-01 09:35:28

这归结为成本与体验之间的权衡。

如果您拥有专业知识,我肯定会研究某种形式的基于云的基础架构,例如 Google App Engine。您使用哪个云平台取决于您使用不同语言的经验(例如 AppEngine 仅适用于 Python/Java)。但一般来说,可扩展的基于云的平台有更多的“陷阱”并且需要更多的专业知识,因为它们专门针对高端可扩展性进行了调整(因此在某些情况下需要企业级概念的知识)。

如果您想尽可能快速、简单地启动并运行,我个人会选择 CakePHP 安装。设置模型数据来表示您正在管理的基本实体,然后使用 CakePHP 的奇妙的约定魔法轻松公开这些模型上的 CRUD 更新!

It comes down to a tradeoff between cost vs experience.

if you have the expertise, I would definitely look into some form of cloud based infrastructure, something like Google App Engine. Which cloud platform you go with depends on what experience you have with different languages (AppEngine only works with Python/Java for e.g). Generally though, scalable cloud based platforms have more "gotchas" and need more know-how, because they are specifically tuned for high-end scalability (and thus require knowledge of enterprise level concepts in some cases).

If you want to be up and running as quickly and simply as possible I would personally go for a CakePHP install. Setup the model data to represent the basic entities you are managing, then use CakePHP's wonderful convention-loving magic to expose CRUD updates on these models with ease!

晨曦慕雪 2024-10-01 09:35:28

与使用 HTTP 的方式相比,用于实现 REST 服务的技术对性能和托管成本的影响要小得多。学习利用 HTTP 不仅仅是学习如何使用 GET、PUT、POST 和 DELETE。

使用您已经了解的任何服务器端技术,并花一些时间阅读 RFC2616。您将为自己节省大量时间和金钱。

The technology you use to implement the REST services will have a far less significant impact on performance and hosting costs than the way you use HTTP. Learning to take advantage of HTTP is far more than simply learning how to use GET, PUT, POST and DELETE.

Use whatever server side technology you already know and spend some quality time reading RFC2616. You'll save yourself a ton of time and money.

怪我入戏太深 2024-10-01 09:35:28

在您的情况下,每个请求都会访问其数据库服务器。因此,即使您有编译语言(例如 C# 或 java),也没有多大关系(除非您正在进行一些数据转换或处理)。

因此数据库服务器必须具有良好的可扩展性。在这里,您选择的语言和数据库应该与主机操作系统进行良好配置。

简而言之,如果您要发送/接收 JSON 字符串并以最少的数据处理在数据库中存储/检索,那么 PHP+MySQL 是很好的选择。

下一个应用程序变得流行,如果您的应用程序不需要频繁更新现有数据,那么您可以将这些数据移动到非常高可扩展的数据库,如 MongoDB(JSON 友好)。

In your case its database server that's accessed on each request. so even if you have compiled language (say C# or java) it wont matter much (unless you are doing some data transformation or processing).

So DB server have to scale well. here your choice of language and DB should be well configured with host OS.

In short PHP+MySQL is good if you are sending/receiving JSON strings and storing/retrieving in DB with minimum data processing.

next app gets popular and if your app don't require frequent updates to existing data then you can move such data to very high scalable databases like MongoDB (JSON friendly).

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