首页 \ 问答 \ PHP在页面关闭时执行代码(PHP execute code on page close)

PHP在页面关闭时执行代码(PHP execute code on page close)

我试图找到一种方法来执行一些PHP代码,一旦用户关闭该页面。 在我的应用程序中,一旦用户关闭或导航离开页面,服务器将在数据库中声明用户为“离线”。 这要求代码知道用户何时离开页面导航。 我的应用程序也有无尽的负载(即它会睡觉,直到用户关闭页面)。

编辑:

感谢您的答案。 我决定采用Pekka的会话方法,因为这对我的应用来说似乎是最合乎逻辑的。

干杯


I am trying to find a method to execute some PHP code once a user closes the page. In my application, once the user closes or navigates away from the page the server will state the user as 'Offline' in the database. This requires the code to know when the user has navigated away from the page. My application also has an endless load (i.e. it will sleep until the user closes the page).

Edit:

Thanks for the answers. I decided to go with Pekka's session method, as this seemed the most logical for my application.

Cheers


原文:https://stackoverflow.com/questions/4864508
更新时间:2023-08-18 09:08

最满意答案

我想你要求的是这样的

float timeWalking = 1.0f;
void Update () {
    rb.velocity = new Vector2(3, rb.velocity.y);

    if (Input.GetMouseButtonDown(0) && onGround)
    {
        timeWalking += Time.deltaTime;
        rb.velocity = new Vector2(rb.velocity.x, 3) * timeWalking;

    }
    if (Input.GetMouseButtonUp(0) && onGround)
          timeWalking = 1.0f;
}

I think what you are asking for it's something like this

float timeWalking = 1.0f;
void Update () {
    rb.velocity = new Vector2(3, rb.velocity.y);

    if (Input.GetMouseButtonDown(0) && onGround)
    {
        timeWalking += Time.deltaTime;
        rb.velocity = new Vector2(rb.velocity.x, 3) * timeWalking;

    }
    if (Input.GetMouseButtonUp(0) && onGround)
          timeWalking = 1.0f;
}

相关问答

更多
  • 而不是标准化或缩放:钳制。 Vector3 input = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")); Vector3 moveDirection = new Vector3( Mathf.Clamp(input.x, -Mathf.Abs(input.normalized.x), Mathf.Abs(input.normalized.x)), 0, Mathf.Clamp(input ...
  • 我想你要求的是这样的 float timeWalking = 1.0f; void Update () { rb.velocity = new Vector2(3, rb.velocity.y); if (Input.GetMouseButtonDown(0) && onGround) { timeWalking += Time.deltaTime; rb.velocity = new Vector2(rb.velocity.x, 3) * time ...
  • 你在bunny1move中创建它后立即调用mv,但是在每次调用mv之后它会设置一个超时,以便在一秒后再次调用它自己。 在再次调用之后,它会设置一个新的超时,以便在下一秒后调用自身,依此类推。 这一系列的呼叫无限延伸。 这本身并不会太糟糕,实际上它似乎是你想要的,让mv每秒都调用。 当你每两秒调用一次bunny1move时会出现问题,这些对bunny1move的重复调用都会创建一个新的mv链并且它们都堆叠在前面的链之上。 因此,兔子在每次迭代中移动得越来越远,而且正在创建越来越多的mv链,并且它们都被同步调用 ...
  • Aziz,我建议检查以下文档,它提供了有关用于ML的特定VM的信息: https : //azure.microsoft.com/en-us/services/virtual-machines/data-science-virtual- machines / ,选择你想要的操作系统,然后点击Plan + Pricing,它会根据存储类型,CPU,RAM等等给你实例的成本。 Aziz, I'd recommend checking the following documentation, it provide ...
  • 雅虎保持速度优化的良好总结: http://developer.yahoo.com/performance/rules.html 您可以使用FireSug插件YSlow来测量您的网站: http://developer.yahoo.com/yslow/ Yahoo maintain a good summary of speed optimisations: http://developer.yahoo.com/performance/rules.html You can measure your site ...
  • 为将来遇到同样问题的人添加答案。 随着图像改变大小,捏移动速度随之增大或减小。 为了补偿这一点并使图像以相同的速度不断移动,需要相对于缩放修改图像转换的量。 我建议用比例因子scaleImage.ScaleX划分翻译 translateImage.X += ( e.DeltaManipulation.Translation.X / scaleImage.ScaleX); OP通过调整这个并通过scaleImage.ScaleX乘以得到所需结果来找到解决方案: translateImage.X += ( e ...
  • 使用二维向量。 像这样的东西: movement = new Vector2D(); if (moveLeft) movement.x += 1; if (moveRight) movement.x -= 1; if (moveUp) movement.y -= 1; if (moveDown) movement.y += 1; movement.normalize(); // Caps the movement vector at a length of one, even when it's a ...
  • 我与tomfanning,这听起来像延迟问题(假设你是以一种理智的方式服务于django应用程序,并且服务器没有被加载太多)。 我会将ping添加到要尝试的列表中,并检查基准网络延迟。 当您从服务器机器本身查询服务时,还要检查速度,以确保它是网络延迟。 如果不是网络,则可以在cProfile( python -m cProfile start_the_server.py )下运行django开发服务器,运行几个查询,然后按Ctrl-C以获取逐个函数的分析信息。 最后一个想法是,python中的XML序列化的 ...
  • 我假设你想知道连续运动之间的速度,而不是一系列运动的平均速度。 如果你有其他要求,理论应该很容易适应。 你需要知道三件事: 现在的触摸在哪里? 以前的触摸在哪里? 从那时起已经过了多少时间? 然后只需使用毕达哥拉斯来获得你的距离,并按时间划分速度。 当您获得touchesMoved事件时,它将为您提供当前和之前的位置。 所有你需要添加的是时间的量度。 为此,你需要在你的类中有一个NSDate属性来帮助计算时间间隔。 您可以在viewDidLoad / viewDidUnload中初始化并释放它,或者在类似的 ...
  • 你的问题不在于速度,你的问题是你在屏幕上移动如此之快,以至于你的触摸不再识别它下面的节点,因为节点实际上不在它下面。 如何处理这个问题是在触摸开始事件中,您检查一个节点,并将此节点分配给一个变量。 然后在触摸移动事件中,更新新变量。 最后在触摸结束时清除变量。 请注意,您需要处理此代码,以实现多点触控等功能 var movingNode : SKNode? override func touchesBegan(touches: Set, withEvent event: UIEvent?) ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)