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
最满意答案
我想你要求的是这样的
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 ...
-
提高移动速度(Increasing movement speed)[2022-11-12]
我想你要求的是这样的 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?) ...