简体   繁体   中英

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 share reaches to $55 so now the 20 share should be sell automatically.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM