我有一个脚本每分钟在我的服务器上运行一次,基本上是一个 cron 作业,为我为一些 friend 制作的小游戏更新数据库中的一些变量。
我遇到的问题是该脚本仅运行某些查询但无法更新其他查询。我已验证它正在连接,但比较无效。任何帮助将不胜感激。
这是我当前无法正常通话的电话。
//Query server
$query = "SELECT id, usr, dt, is_online FROM player_data WHERE is_online =1";
$result = mysqli_query($conn, $query);
// If connection is good
if ($result = mysqli_query($conn, $query))
{
echo "Connected </br>";
/* fetch associative array */
while ($row = mysqli_fetch_assoc($result))
{
//Get time of NOW, and time of last activity
echo "loop started </br>";
$now = strtotime(date("Y-m-d h:i:s", strtotime("now")));
$before = strtotime(date("Y-m-d h:i:s", strtotime($row['dt'])));
//Add five minutes to the last activity
$then = $before + (60 * 5);
//Display the times
echo $before . "</br>";
echo $now . "</br>";
echo $then . "</br>";
//determine if the time now is more then 5 minutes after the last activity
if (strtotime($now) > strtotime($then))
{
//set user to offline if more then 5 minutes has passed.
mysqli_query($conn, "UPDATE player_data SET is_online = 0");
echo "1.User: " . $row['usr'] . "</br>";
echo "1.Database: " . $row['dt'] . "</br>";
echo "1.System: " . date('Y-m-d H:i:s') . "</br>";
echo "Now: " . $now . "</br>";
echo "Before: " . $before . "</br>";
echo "then: " . $then . "</br>";
}
}
}
`````````````````````````````````````````````````````````````````````````
this should set anyone who has not been active in the last 5 minutes to is_online = 0 but does not.
This is the actual output as of right now with the last activity being more then 1.5 hours earlier.
Connected
loop started
1555687200
1555777824
1555687500
loop started
1555687227
1555777824
1555687527
最佳答案
好吧,让我猜猜,脚本是将所有人设置为离线,对吧?
问题是您在我们的 UPDATE 语句中错过了 WHERE 子句
mysqli_query($conn, "UPDATE player_data SET is_online = 0");
所以最好复习那部分。应该是这样的
mysqli_query($conn, "UPDATE player_data SET is_online = 0 WHERE id = " . $row['usr']);
也没有必要比较 strtotime($now) 和 strtotime($then):$now 和 $then 已经保存了“microtime”值,所以你可以这样做:
if ($now > $then) {
//your code here
}
顺便说一句,即使您没有使用任何REQUEST 参数,我也建议您使用准备好的语句。
关于php/mysqli 查询没有执行一些没有错误的查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55770284/
我在使用omniauth/openid时遇到了一些麻烦。在尝试进行身份验证时,我在日志中发现了这一点:OpenID::FetchingError:Errorfetchinghttps://www.google.com/accounts/o8/.well-known/host-meta?hd=profiles.google.com%2Fmy_username:undefinedmethod`io'fornil:NilClass重要的是undefinedmethodio'fornil:NilClass来自openid/fetchers.rb,在下面的代码片段中:moduleNetclass
我正在用Ruby编写一个简单的程序来检查域列表是否被占用。基本上它循环遍历列表,并使用以下函数进行检查。require'rubygems'require'whois'defcheck_domain(domain)c=Whois::Client.newc.query("google.com").available?end程序不断出错(即使我在google.com中进行硬编码),并打印以下消息。鉴于该程序非常简单,我已经没有什么想法了-有什么建议吗?/Library/Ruby/Gems/1.8/gems/whois-2.0.2/lib/whois/server/adapters/base.
大约一年前,我决定确保每个包含非唯一文本的Flash通知都将从模块中的方法中获取文本。我这样做的最初原因是为了避免一遍又一遍地输入相同的字符串。如果我想更改措辞,我可以在一个地方轻松完成,而且一遍又一遍地重复同一件事而出现拼写错误的可能性也会降低。我最终得到的是这样的:moduleMessagesdefformat_error_messages(errors)errors.map{|attribute,message|"Error:#{attribute.to_s.titleize}#{message}."}enddeferror_message_could_not_find(obje
我好像记得Lua有类似Ruby的method_missing的东西。还是我记错了? 最佳答案 表的metatable的__index和__newindex可以用于与Ruby的method_missing相同的效果。 关于ruby-难道Lua没有和Ruby的method_missing相媲美的东西吗?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/7732154/
我有一个奇怪的问题:我在rvm上安装了rubyonrails。一切正常,我可以创建项目。但是在我输入“railsnew”时重新启动后,我有“程序'rails'当前未安装。”。SystemUbuntu12.04ruby-v"1.9.3p194"gemlistactionmailer(3.2.5)actionpack(3.2.5)activemodel(3.2.5)activerecord(3.2.5)activeresource(3.2.5)activesupport(3.2.5)arel(3.0.2)builder(3.0.0)bundler(1.1.4)coffee-rails(
我想在一个没有Sass引擎的类中使用Sass颜色函数。我已经在项目中使用了sassgem,所以我认为搭载会像以下一样简单:classRectangleincludeSass::Script::FunctionsdefcolorSass::Script::Color.new([0x82,0x39,0x06])enddefrender#hamlengineexecutedwithcontextofself#sothatwithintemlateicouldcall#%stop{offset:'0%',stop:{color:lighten(color)}}endend更新:参见上面的#re
我遵循了教程http://gettingstartedwithchef.com/,第1章。我的运行list是"run_list":["recipe[apt]","recipe[phpap]"]我的phpapRecipe默认Recipeinclude_recipe"apache2"include_recipe"build-essential"include_recipe"openssl"include_recipe"mysql::client"include_recipe"mysql::server"include_recipe"php"include_recipe"php::modul
我遵循MichaelHartl的“RubyonRails教程:学习Web开发”,并创建了检查用户名和电子邮件长度有效性的测试(名称最多50个字符,电子邮件最多255个字符)。test/helpers/application_helper_test.rb的内容是:require'test_helper'classApplicationHelperTest在运行bundleexecraketest时,所有测试都通过了,但我看到以下消息在最后被标记为错误:ERROR["test_full_title_helper",ApplicationHelperTest,1.820016791]test
我知道我可以指定某些字段来使用pluck查询数据库。ids=Item.where('due_at但是我想知道,是否有一种方法可以指定我想避免从数据库查询的某些字段。某种反拔?posts=Post.where(published:true).do_not_lookup(:enormous_field) 最佳答案 Model#attribute_names应该返回列/属性数组。您可以排除其中一些并传递给pluck或select方法。像这样:posts=Post.where(published:true).select(Post.attr
我是rails的新手,想在form字段上应用验证。myviewsnew.html.erb.....模拟.rbclassSimulation{:in=>1..25,:message=>'Therowmustbebetween1and25'}end模拟Controller.rbclassSimulationsController我想检查模型类中row字段的整数范围,如果不在范围内则返回错误信息。我可以检查上面代码的范围,但无法返回错误消息提前致谢 最佳答案 关键是您使用的是模型表单,一种显示ActiveRecord模型实例属性的表单。c