Table of Contents
回复讨论(解决方案)
Home Backend Development PHP Tutorial 服务器端时间刷新

服务器端时间刷新

Jun 23, 2016 pm 02:19 PM

手机游戏 服务器 前端

小弟是做手游的 想请教下 
前端请求我服务器端的时间 
我应该传给他当前我服务器端的实时时间 
所以我应该时时刷新自己 那么如何实时刷新 
都有什么方案
需尽量少的占用资源

回复讨论(解决方案)

恕我不懂,php里边直接用time()函数不能直接获取当前时间的时间戳吗? 再用date()格式化一下输出给前端

难道里边还有什么关窍...

因为游戏时间要走服务器时间 不能走客户端的 所以要服务器端时时刷新时间给前端
走客户端 玩家一改手机时间 就等于调游戏时间了 就扯淡了
比如 有的游戏每天让你抽一次奖 然后提示离下次抽奖还剩XX小时XX分XX秒
这个时间得我这边服务器端给吧
形象化的说:前端每次向我请求“到时间了没啊?”我就得告诉他“到了”或者“没到”吧。。他如果隔一会就问我一遍 我得时时刷新自己的时间 才能追赶上他的请求的频率吧....大概是这个意思

你的“形象化的说”也不失是一种方案,但不是你刷新时间(时间是客观存在的)只不过你用你的方式表现出来
通常并不这样做,而是在开始的时候发送服务器时间给用户,用于计算用户时间与服务器时间的时间差。这样的js倒计时的代码很多,你可去找一下

版大说的没错 

而且你可以在真正"领奖"的时候再去判断一下是否在时间范围内就可以了

服务器上用time()获取的应该总是当前服务器时间吧?@xuzuning

刚才问了下头儿 他说做一个批处理文件 bat文件 
什么stop 什么loop..这方案行么 没搞过啊 - -

版大说的没错 

而且你可以在真正"领奖"的时候再去判断一下是否在时间范围内就可以了

服务器上用time()获取的应该总是当前服务器时间吧?@xuzuning

time()获取的是服务器的时间。可以这样做:开始的时候把服务器的时间传过去,然后在验证的时候以服务器的时间为准,客户端那边怎么稻谷无所谓,毕竟判定是否成功的关键因素在服务器的手里。

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Working with Flash Session Data in Laravel Working with Flash Session Data in Laravel Mar 12, 2025 pm 05:08 PM

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-

cURL in PHP: How to Use the PHP cURL Extension in REST APIs cURL in PHP: How to Use the PHP cURL Extension in REST APIs Mar 14, 2025 am 11:42 AM

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.

Simplified HTTP Response Mocking in Laravel Tests Simplified HTTP Response Mocking in Laravel Tests Mar 12, 2025 pm 05:09 PM

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' =>

12 Best PHP Chat Scripts on CodeCanyon 12 Best PHP Chat Scripts on CodeCanyon Mar 13, 2025 pm 12:08 PM

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: Best Practices for PHP Log Analysis PHP Logging: Best Practices for PHP Log Analysis Mar 10, 2025 pm 02:32 PM

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

Explain the concept of late static binding in PHP. Explain the concept of late static binding in PHP. Mar 21, 2025 pm 01:33 PM

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

Customizing/Extending Frameworks: How to add custom functionality. Customizing/Extending Frameworks: How to add custom functionality. Mar 28, 2025 pm 05:12 PM

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

Framework Security Features: Protecting against vulnerabilities. Framework Security Features: Protecting against vulnerabilities. Mar 28, 2025 pm 05:11 PM

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

See all articles