开发者

how to automatically detect a value for my user even if user not logged in

I am developing a stock market game. So for this purpose I am fetching data from stock market using an API.

In this game user can sell his/her share at the current price of that share in stock market or at any other specific price(decided by user).

So for example:

The Current Price for Google Share is $50.

The user wants to sell his 20 shares when the price reaches to $55.

So he fills a form on my website and set 20 shares to sell at the price of $55 and just log out from his account.

Suppose after 20 min the market price of Google sha开发者_如何学JAVAre reaches to $55 so now the 20 share should be sell automatically.

SO now My Question is that:

How can I automatically detect at a periodic interval that share's prices reaches to $55 or not and if yes then the 20 shares should be sell automatically.

I am using PHP,Js,Mysql,AJAX and linux server.


the only other way would be to have the same script you would have used for cron job, run on every page load...and then it would be run whenever any user goes to a page. This of course is not ideal because if there is a lot of traffic, it gets needlessly triggered over and over...but no traffic would mean no triggering. Or maybe one person goes to a page every hour..script won't run for an hour.

I suppose another way would be to have your own dedicated browser open and a make a page to request the script and refresh every X seconds, via meta tag or js or whatever.

But anyways, why not use a cron job? That's what it's there for.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜