我正在尝试使用Akka HTTP来基本验证我的请求.碰巧我有一个外部资源来进行身份验证,因此我必须对此资源进行休息调用.
这需要一些时间,并且在处理时,我的API的其余部分似乎被阻止,等待此调用.我用一个非常简单的例子重现了这个:
// used dispatcher:
implicit val system = ActorSystem()
implicit val executor = system.dispatcher
implicit val materializer = ActorMaterializer()
val routes =
(post & entity(as[String])) { e =>
complete {
Future{
Thread.sleep(5000)
e
}
}
} ~
(get & path(Segment)) { r =>
complete {
"get"
}
}
Run Code Online (Sandbox Code Playgroud)
如果我发布到日志端点,我的get端点也会等待5秒,这是日志端点所指示的.
这是预期的行为,如果是,如何在不阻止整个API的情况下进行阻止操作?
我遇到PDO Prepared语句的问题,如果你需要多次使用相同的绑定变量,查询将不会验证.
例:
$params = array (
':status' => $status,
':userid' => $_SESSION['userid']
);
$stmt = $pdo->prepare ('
INSERT INTO
tableName
( userId, status )
VALUES
( :userid, ":status" )
ON DUPLICATE KEY UPDATE
status = ":status"
');
if ( ! $stmt->execute ( $params ))
{
print_r( $stmt->errorInfo ());
}
Run Code Online (Sandbox Code Playgroud)
编辑:的价值$params是:
Array ( [:status] => PAID [:userid] => 111 )
编辑2:
我注意到,而不是原始值,而不是userid,插入0,而不是状态插入空字符串.
我在OS X上使用MAMP运行Laravel,我正在尝试使用PHPUnit和sqlite进行一些单元测试,但是当我运行测试时,我得到了错误
一般错误:1没有这样的表:用户
我已经尝试运行工匠,手动迁移数据库,使用--env = testing,运行正常,但我仍然得到错误.我甚至调用Artisan::call('migrate');了SetUp方法.
/app/config/testing/database.php
return [
'default' => 'sqlite',
'connections' => [
'sqlite' => [
'driver' => 'sqlite',
'database' => ':memory:',
'prefix' => ''
],
]
];
Run Code Online (Sandbox Code Playgroud)
编辑: 迁移文件:
Schema::create('users', function($table) {
$table->increments('id');
$table->string('email', 32)->unique();
$table->string('password', 64);
$table->string('username', 32)->unique();
$table->dateTime('birthdate');
$table->enum('status', array('ACTIVE', 'INACTIVE'));
$table->timestamps();
});
Schema::create('roles', function($table) {
$table->increments('id');
$table->string('name', 32);
});
Schema::create('role_user', function ($table) {
$table->increments('id');
$table->unsignedInteger('user_id');
$table->unsignedInteger('role_id');
$table->foreign('user_id')->references('id')->on('users');
$table->foreign('role_id')->references('id')->on('roles');
});
Run Code Online (Sandbox Code Playgroud) 在输入函数之前,我想检查参数匹配的类型。
function ((int) $integer, (string) $string ) { /*...*/ }
Run Code Online (Sandbox Code Playgroud)
相对于
function ( $int, $string ) {
$string = (string) $string;
$int = (int) $int;
}
Run Code Online (Sandbox Code Playgroud)
有没有办法做到这一点?我也推测这样做是作为对象
function ( Integer $int ) { /*...*/ }
Run Code Online (Sandbox Code Playgroud)
通过这样做,我可以发送一个,functionName ( new Integer ( $int ));但我希望没有添加的语法。
我想能够在程序启动时有一个空数组,在运行时填充它,并删除它内部的东西.这可能必须是一个多维数组.那么,我该怎么做?
防爆.
int randomNumber;
int RandomString;
int array[] = {};
for(int i;int i < 10; int i ++){
array + random variable;
array + random string;
}
Run Code Online (Sandbox Code Playgroud)
所以,看起来像:
array [] = {{randomint,randomstring},{randomint,rrandomstring}}
这可能吗?