小编Sti*_*vni的帖子

为什么应该关闭或保持 Redis 连接打开?

我在 PHP 项目中使用 Redis。我使用 phpredis 作为客户端。有时,在较长的 CLI 脚本中,我会遇到 PHP 分段错误。

我之前就遇到过phpredis在连接超时的时候出现问题。由于我的 Redis 配置被配置为在 300 秒后自动关闭空闲连接,我猜这会导致分段错误。

为了能够选择是增加连接超时还是默认为0(这意味着“永不超时”),我想知道可能的优点和缺点是什么?

为什么我永远不应该关闭连接?
为什么我应该确保连接不保持打开状态?

谢谢

php timeout segmentation-fault redis phpredis

6
推荐指数
1
解决办法
1万
查看次数

我只能使用OWIN UseStaticFiles提供一个文件

我正在使用OWIN来从Windows服务中通过http提供静态内容.(为Windows服务嵌入Web管理工具).

我经历了一些奇怪的行为:

  • 当我运行该服务时,我只能访问"web"文件夹中的一个文件,浏览器中的每个连续调用结果都会告诉该页面不可用(ERR_CONNECTION_RESET).
  • 嵌入式WebApi 保持可访问状态.
  • 当我使用相同的地址和端口重新启动服务时,文件保持不可见.
  • 当我重新启动另一个端口的服务,我可以访问的文件一次 ...

顺便说一下,此"web"文件夹中的此文件被设置为"复制到输出目录"属性的"始终复制".

谁知道出了什么问题?

在这里看我的StartUp配置类

public class WebStartUp
{
    public void Configuration(IAppBuilder app)
    {
        string staticFilesDir = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "web");
        app.UseStaticFiles(staticFilesDir);

        HttpConfiguration config = new HttpConfiguration();
        config.Routes.MapHttpRoute(
            name: "DefaultApi",
            routeTemplate: "api/{controller}/{id}",
            defaults: new { id = RouteParameter.Optional }
        );
        app.UseWebApi(config);
    }
}
Run Code Online (Sandbox Code Playgroud)

在这里看到我托管它的Windows服务......

    public partial class MyService : ServiceBase
    {
        private IDisposable webApp;
        private const string ServiceAddress = "http://localhost:2345";

        public MyService()
        {

        }

        protected override …
Run Code Online (Sandbox Code Playgroud)

.net owin

5
推荐指数
1
解决办法
6438
查看次数

为什么Symfony仍然会记录到dev.log文件,即使我没有在loghandler中定义它?

在执行Symfony命令期间,我想将消息记录到另一个文件.我已经阅读了Symfony和Monolog文档,它应该像我在这里描述的那样工作.(请注意,我知道来自'doctrine','event',...频道的消息仍将由主处理程序记录,但这对我来说无关紧要)

在我config.yml,我有这个:

monolog:
    channels: [commandline]
    handlers:
        main:
            type:  stream
            path:  "%kernel.logs_dir%/%kernel.environment%.main.log"
            level: debug
            channels: [!commandline]
        commandline:
            type:  stream
            path:  "%kernel.logs_dir%/%kernel.environment%.commandline.log"
            level: debug
            channels: commandline
        stdout:
            type:  stream
            path:  "php://stdout"
            level: debug
            channels: commandline
        mail:
            type:         stream
            action_level: alert
            handler:      buffered_mail
        buffered_mail:
            type:    buffer
            handler: swift
        swift:
            type:       swift_mailer
            from_email: some@email.com
            to_email:   some@email.com
            subject:    "Something went wrong"
            level:      alert
Run Code Online (Sandbox Code Playgroud)

我期待有2个日志文件:dev.main.logdev.commandline.log.但是我还有第三个日志文件:dev.log记录所有消息.我似乎没有找到定义loghandler的位置以及如何阻止它记录事物......

如果有人能指出我正确的方向,那就太好了!

顺便说一句,我正在使用:

  • symfony 2.3
  • monolog-bundle 2.4

编辑

没有任何monolog部分config_dev.yml

php logging symfony monolog

5
推荐指数
1
解决办法
6242
查看次数

CakePHP 2.x插件和插件文件夹之间有什么区别?

从CakePHP 2.0开始,文件夹结构如下:

- MyApplicationName
--- app
---- 插件
----(其他文件夹......)
--- lib
--- 插件
---供应商

app-folder中的Plugin -folder或应用程序根文件夹中的plugins -folder 之间有什么区别吗?

这些文件夹的推荐使用是什么?或者你可以按照自己的意愿使用它们吗?

很抱歉,如果这是一个经常性的问题,但快速搜索没有提供任何类似的问题...

php plugins cakephp cakephp-2.0 cakephp-2.1

4
推荐指数
1
解决办法
1013
查看次数

用Symfony形式分离关注点

我最近一直在尝试使用Symfony 2表单,这对于简单表单非常有用.

但是 - 在选择框或类似的东西中使用 - 我经常需要表单中的关联实体列表.在几篇博文和Symfony文档中,他们提出了类似这样的内容......

//BlogPostType implements FormTypeInterface
public function buildForm(FormBuilderInterface $builder, array $options)
{
  $builder
  ->add('category', null, array(
    'property' => 'name',
    'query_builder' => function(EntityRepository $er) use($options) {
      return $er->createQueryBuilder('category')->orderBy('category.name', 'ASC');
    }
  );
}
Run Code Online (Sandbox Code Playgroud)

由于我非常关注域驱动设计,特别是关注点的分离,我发现很难相信将关联实体绑定到Symfony中的自定义表单类型的唯一选择是通过在自定义中查询它表格类型.

在我看来,这违反了SoC,因为表格不应该是查询.这样,表单总是采用相同的实体,但不是应该选择显示哪些实体的表单...

要求表单构建器构建表单的控制器应该将关联的对象注入自定义表单类型构造函数中......

//BlogPostType implements FormTypeInterface
public function __construct(array $categories) {
  $this->categories = $categories;
}

public function buildForm(FormBuilderInterface $builder, array $options)
{
  $builder
    ->add('category', null, array(
      'property' => 'name',
      'choices' => $this->categories
    );
}
Run Code Online (Sandbox Code Playgroud)

有谁知道如何实现这一目标?

php oop domain-driven-design symfony modular-design

3
推荐指数
1
解决办法
351
查看次数

在树枝中加入对象列表的属性值

是否可以连接对象列表的属性值以显示它?
就像是:

{{ users|join(', ', username) }}
Run Code Online (Sandbox Code Playgroud)

users物体在哪里,有getUsername()方法.
我想join不需要额外的论证,但是有没有解决办法来实现类似的东西?我无法使用该__toString()功能,因为它代表了其他东西......

symfony twig

3
推荐指数
3
解决办法
3892
查看次数