- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我认为这是某处代码的问题,但代码太简单了,我不确定它可能是什么。
我已经验证了 wait_timeout 足够高并且已经检查了这里的所有内容:http://dev.mysql.com/doc/refman/5.1/en/gone-away.html没有任何成功。
这会在一次脚本运行中执行的第二个查询中重复发生,因此我确定这是一个编码错误。
我围绕 PDO 类创建了一个非常简单的包装器来拥有一个单独的数据库句柄:
<?php
class PDOWrapper
{
protected static $instance;
protected $dbh;
function __construct()
{
if ( is_null(static::$instance) )
{
static::$instance = $this;
$this->connect_to_db();
}
}
static function instance()
{
if ( is_null(static::$instance) )
{
new static;
}
return static::$instance;
}
private function connect_to_db()
{
$db_info = array(
0 => array(
'hostname' => "Host",
'username' => "User",
'password' => "Pass",
'db' => "DB",
)
);
//Try to connect to the database
try
{
$dbh = new PDO('mysql:host=' . $db_info[0]['hostname'] . ';dbname=' . $db_info[0]['db'], $db_info[0]['username'], $db_info[0]['password'], array( PDO::ATTR_PERSISTENT => true, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_EMULATE_PREPARES => true ));
}
catch (PDOException $e)
{
log_message("Error connecting to DB!: " . $e->getMessage(), LOG_LEVEL_CRITICAL );
return false;
}
$this->dbh = $dbh;
}
public static function get_dbh()
{
if ( is_null(static::$instance) )
{
new static;
}
return static::$instance->dbh;
}
}
然后我像这样使用包装器:
function somefunc(){
$dbh = PDOWrapper::get_dbh();
$future_sth = $dbh->prepare("SELECT * FROM some_table");
$future_sth->execute();
$ret = $future_sth->fetchAll(PDO::FETCH_ASSOC);
print_r($ret);
$future_sth->closeCursor();
return $ret;
}
我在事件循环中重复调用这个函数。第一次调用它时,print_r 运行良好,并打印出我希望看到的行。
然而,在函数执行一次后,我得到以下信息:
Warning: Error while sending QUERY packet. PID=92871
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000]: General error: 2006 MySQL server has gone away'
我不知道为什么它会“消失”。我的 my.cnf 看起来没问题。等待超时时间很长,无论如何我一运行第二个查询就会立即发生这种情况。有什么想法吗?
在 MySQL 错误日志中看起来没有任何明显错误:
120925 12:48:46 mysqld_safe Starting mysqld daemon with databases from /usr/local/var/mysql
120925 12:48:46 [Warning] The syntax '--log' is deprecated and will be removed in a future release. Please use '--general-log'/'--general-log-file' instead.
120925 12:48:46 [Warning] Setting lower_case_table_names=2 because file system for /usr/local/var/mysql/ is case insensitive
120925 12:48:46 InnoDB: The InnoDB memory heap is disabled
120925 12:48:46 InnoDB: Mutexes and rw_locks use GCC atomic builtins
120925 12:48:46 InnoDB: Compressed tables use zlib 1.2.5
120925 12:48:46 InnoDB: Initializing buffer pool, size = 128.0M
120925 12:48:46 InnoDB: Completed initialization of buffer pool
120925 12:48:46 InnoDB: highest supported file format is Barracuda.
120925 12:48:46 InnoDB: Waiting for the background threads to start
120925 12:48:47 InnoDB: 1.1.8 started; log sequence number 2273680401
120925 12:48:47 [Note] Server hostname (bind-address): '0.0.0.0'; port: 3306
120925 12:48:47 [Note] - '0.0.0.0' resolves to '0.0.0.0';
120925 12:48:47 [Note] Server socket created on IP: '0.0.0.0'.
120925 12:48:47 [Note] Event Scheduler: Loaded 0 events
120925 12:48:47 [Note] /usr/local/Cellar/mysql/5.5.25a/bin/mysqld: ready for connections.
Version: '5.5.25a-log' socket: '/tmp/mysql.sock' port: 3306 Source distribution
最佳答案
我想通了。
我正在使用 pcntl_fork
开发一个多进程守护进程。父进程负责运行一个循环来查询数据库,并派生子进程根据它看到的数据执行额外的工作。
children 不需要数据库连接,但是他们仍然得到了一个,因为使用了 pcntl_fork
。我只是在子进程完成工作后使用 exit()
杀死它们,这导致“友好”的 PHP 清理关闭它认为子进程拥有的事件 MySQL 连接。
控制权将返回给父级,当他们试图在数据库中查找更多数据以发送给子级时,他们会发现他们的数据库连接突然不再有效。
对我来说,解决方法是使用 posix_kill(getmypid(), 9);
来杀死 child 而不是 exit();
。
关于php - PDO/MySQL/PHP/OS X : MySQL server has gone away on subsequent queries?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12587068/
我最近从 mysql_ 切换到 PDO,这真的很痛苦。一切看起来都那么复杂。 过去我开发了一个系统,用户可以导入包含记录的 csv。然后通过 while 循环将这些行导入数据库。它在 mysql_qu
android 布局使用 layout_weight。我的目标是所有组件的 1/3,但有时页脚实际上设置为消失,然后可见。从 gone 设置为 visible 时,权重计算如何工作?我没有看到具有 1
我想要一个小的“标题”,当我单击它时,其余内容会使用向上滑动动画显示。 我已经尝试了一些动画,但我唯一想做的就是在其父级中为内容设置动画。我想要的是,当我单击标题时,整个标题和内容(具有可见性 GON
我使用 Firebase 和 RadioButton 获得 2 种类型的数据,我对显示的数据进行排序。一切似乎都正常,但是当隐藏其中一种数据类型时仍然有一个空白空间。告诉我如何正确隐藏/显示数据。 T
我的 Jersey API 如下: @DELETE @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON
在 VBA Excel 中,如果我在关闭并再次打开文件后使用 UserInterFaceOnly:=True 选项保护工作表,则 UserInterFaceOnly 模式不会激活,只有密码保护。 代码
如果设备设置为英国英语,我不想显示布局。最好的方法是什么?每次获取设备语言? 最佳答案 往这边走,GB代表大不列颠(英国) String locale = context.getResources()
我的布局中有来自设计支持库的 FAB: //....
当我尝试在 Eclipse 中使用图形布局界面(而不是 xml)进行布局时,我遇到了这个问题: 假设我的主要布局只是屏幕底部的一个简单按钮,单击该按钮时,会打开一个覆盖大部分屏幕的文本框。 注意:我这
在我的应用程序中,我有 RelativeLayout 和任何小部件,进入布局,我想通过 xml 动画将其向上移动。 RelativeLayout 可见性为 GONE 并且必须再次将可见性设置为 GON
我的 XMl 中有这段代码。由于某种原因, View 仍然可见。我还有其他 block 可以使其在特定时间点可见,但我已经将它们注释掉了。这是保留此 View 的最后一段代码,出于某种原因我仍然可以看
我有一个包含一个 TextView 和两个图像的相对布局(宽度固定宽度,高度 = 48dip)。当我为一张图片设置 visibility view.gone 时,它不会释放空间 最佳答案
所以我有一个应用程序,当用户点击 button 时,将为带按钮的 layout 执行 animation(例如 滑动菜单),然后如果他点击另一个按钮,它必须使第一个布局不可见或消失,然后是新布局。 但
我想问一下,如何为 Admob 实现 AdListner。我希望广告在点击后消失。我试过了,但没有用。 final AdView ad1 = (AdView) findViewById(R.id.ad
我想将一个 View 设置为 GONE,然后让其他 View 占用剩余空间。 现在,如果我将它设置为 GONE,它会在布局中原来的位置留下一个空间,该 View 是一个具有固定高度的 viewpage
pypi.python.org has been migrated to pypi.org之后,我在尝试像往常一样使用命令将包上传到 PyPI 时遇到错误: python2.7 setup.py sd
我有一个自定义搜索面板,它是主布局的一部分。大多数时候面板是隐藏的。我想在面板上添加出现/消失的动画。这是简化的布局摘录: > > 尝
我遇到了一个问题,即可见性状态为 GONE 的 View (不希望地)占用了屏幕空间。这个问题总是发生在 API 级别 <= 7 的设备上,但最近才发生在 8+ 设备上(在我使用 AsyncTasks
所以我的应用程序中有一个 GLSurfaceView,由 GLSurfaceView.Renderer 渲染并使用 JPCt 作为库。 表面处于不可见的 RelativeLayout 中(可见性:消失
我有一个巨大的 XML 布局,其中有许多 Relative/Linear 布局,我现在正在做的是使用 setVisibility (View. GONE) 并在需要时更改其可见性。 我的问题是:这种方
我是一名优秀的程序员,十分优秀!