Workerman笔记
本文环境 workerman 不懂的可以评论或联系我邮箱:owen@owenzhang.com 著作权归OwenZhang所有。商业转载请联系OwenZhang获得授权,非商业转载请注明出处。
多文件合并下载
$content = file_get_contents($file1);
$content .= file_get_contents($file2);
return response($content)->withHeaders([
'Content-Disposition' => 'attachment; filename=' . urlencode('文件名'),
'Content-Type' => 'application/octet-stream',
]);
页面定向跳转
return redirect($back_url);
return new Response(302, [‘Location’ => $location]);
mysql
$where[] = ['uid', '=', $request->uid];
$where[] = ['is_del', '=', 2];
$where[] = ['os_type', '=', $os_type];
$list = Feedback::getList($where, 'id,content,feedback_imgs,status,c_time,uid', 'id desc', 1, 10);
$info = Feedback::getOne($where);
$data = [
'uid' => $request->uid,
'status' => 3,
];
Feedback::insert($data);
Feedback::updateDataCache($where, $data);
Feedback::where('uid', $uid)->delete();
try {
$res = (new UserCollection())->insert($data);
return $res ? $this->apiSuccess() : $this->apiFailed();
} catch (\Throwable $e) {
return $this->apiFailed();
}
use think\facade\Db;
// 启动事务
Db::startTrans();
try {
$data = [
'u_time' => myDate(),
'is_del' => 1,
];
Db::table('banner')->whereIn('id', $ids)->update($data);
Db::table('user')->whereIn('id', $ids)->update($data);
// 提交事务
Db::commit();
$save = true;
} catch (\Throwable $e) {
// 回滚事务
Db::rollback();
$errorMessage = $e->getMessage();
$save = false;
}
redis
//string
Redis::set(ADMIN_TOKEN_LOGIN . $jwt, json_encode($data), 'EX', 60 * 60 * 24 * 1, 1);
linux系统下workerman如何开机自动启动
查看php命令 执行目录 打开命令行工具,执行以下命令
whereis php
我这里执行后输出 /user/bin/php
打开 /etc/rc.d/rc.local,在exit 0前添加类似以下代码
/user/bin/php /项目磁盘/路径/start.php start -d
exit 0
或者 /usr/bin/env php /www/wwwroot/owenzhang/start.php start -d
webman里面如何输出文件到php://output
$writer = new Xlsx($spreadsheet);
$response = response();
ob_start();
$writer->save('php://output');
$c = ob_get_contents();
ob_flush();
flush();
$response->withHeaders([
'Content-Type' => 'application/vnd.ms-excel',
'Content-Disposition' => 'attachment;filename="xxx.xlsx"',
'Cache-Control' => 'max-age=0',
])->withBody($c);
return $response;
Buy me a cup of coffee 🙂
觉得对你有帮助,就给我打赏吧,谢谢!