服务器端时间刷新
手机游戏 服务器 前端
小弟是做手游的 想请教下前端请求我服务器端的时间
我应该传给他当前我服务器端的实时时间
所以我应该时时刷新自己 那么如何实时刷新
都有什么方案
需尽量少的占用资源
回复讨论(解决方案)
恕我不懂,php里边直接用time()函数不能直接获取当前时间的时间戳吗? 再用date()格式化一下输出给前端
难道里边还有什么关窍...
因为游戏时间要走服务器时间 不能走客户端的 所以要服务器端时时刷新时间给前端
走客户端 玩家一改手机时间 就等于调游戏时间了 就扯淡了
比如 有的游戏每天让你抽一次奖 然后提示离下次抽奖还剩XX小时XX分XX秒
这个时间得我这边服务器端给吧
形象化的说:前端每次向我请求“到时间了没啊?”我就得告诉他“到了”或者“没到”吧。。他如果隔一会就问我一遍 我得时时刷新自己的时间 才能追赶上他的请求的频率吧....大概是这个意思
你的“形象化的说”也不失是一种方案,但不是你刷新时间(时间是客观存在的)只不过你用你的方式表现出来
通常并不这样做,而是在开始的时候发送服务器时间给用户,用于计算用户时间与服务器时间的时间差。这样的js倒计时的代码很多,你可去找一下
版大说的没错
而且你可以在真正"领奖"的时候再去判断一下是否在时间范围内就可以了
服务器上用time()获取的应该总是当前服务器时间吧?@xuzuning
刚才问了下头儿 他说做一个批处理文件 bat文件
什么stop 什么loop..这方案行么 没搞过啊 - -
版大说的没错
而且你可以在真正"领奖"的时候再去判断一下是否在时间范围内就可以了
服务器上用time()获取的应该总是当前服务器时间吧?@xuzuning
time()获取的是服务器的时间。可以这样做:开始的时候把服务器的时间传过去,然后在验证的时候以服务器的时间为准,客户端那边怎么稻谷无所谓,毕竟判定是否成功的关键因素在服务器的手里。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

PHP logging is essential for monitoring and debugging web applications, as well as capturing critical events, errors, and runtime behavior. It provides valuable insights into system performance, helps identify issues, and supports faster troubleshoot

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

The article discusses adding custom functionality to frameworks, focusing on understanding architecture, identifying extension points, and best practices for integration and debugging.

Article discusses essential security features in frameworks to protect against vulnerabilities, including input validation, authentication, and regular updates.
