我有一个使用spl_autoload_register()以下注册的自动加载器:
class MyAutoLoader{
public function __construct(){
spl_autoload_register(array($this, 'loader'));
}
public function loader($className){
var_dump($className);
}
}
$al = new MyAutoLoader(); //Register the autoloader
Run Code Online (Sandbox Code Playgroud)
从var_dump(),自动加载器似乎被调用很多东西,数据要插入到数据库中,参数化的SQL查询以及不是:
string 'name' (length=4)
string 'a:2:{s:5:"label";s:4:"Name";s:8:"required";b:1;}' (length=48)
string 'en_US' (length=5)
string 'object' (length=6)
string 'name = ?' (length=8)
Run Code Online (Sandbox Code Playgroud)
这些东西永远不会是类,所以永远不应该使用new或class_exists()等等.
在什么情况下/函数调用是自动加载器调用?我想停止自动加载不是被调用类的"classNames",因为每个$className都被使用检查file_exist(),并且检查这些数据字符串是非常低效的.
问题解决了.我首先按照Brad的建议进行了回溯,并将跟踪转储到文件中(只需添加一个打开文件并附加到其上的小片段).
显然,痕迹非常大,但我选择了我能找到的最简单的一条.顺便说一下,这个跟踪碰巧是一个调用我编写的数据库(ORM)包装器来包装真棒RedBean ORM库的.我转储的结果$className也验证了,因为这些字符串是数据进出数据库.
话虽如此,我有一个__call()拦截我的数据库包装器的方法,做一些处理,将它传递给RedBean,处理结果,然后将其发送回调用者.
问题:在处理过程中,我正在调用is_subclass_of()和instanceof,这显然会要求自动加载器尝试加载类(因为我们没有任何名为name =?loaded的类,也不存在).
解决方案是实际确保我们有一个object之前的呼叫is_subclass_of()和instanceof: …
我有一个简单的https服务器服务于这样的简单页面(为简洁起见,没有错误处理):
package main
import (
"crypto/tls"
"fmt"
"net/http"
)
func main() {
mux := http.NewServeMux()
mux.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
fmt.Fprintf(w, "hello!")
})
xcert, _ := tls.LoadX509KeyPair("cert1.crt", "key1.pem")
tlsConf := &tls.Config{
Certificates: []tls.Certificate{xcert},
}
srv := &http.Server{
Addr: ":https",
Handler: mux,
TLSConfig: tlsConf,
}
srv.ListenAndServeTLS("", "")
}
Run Code Online (Sandbox Code Playgroud)
我想使用Let的加密 TLS证书来通过https提供内容.我希望能够在没有任何停机的情况下进行证书续订并在服务器中更新证书.
我尝试运行goroutine来更新tlsConf:
go func(c *tls.Config) {
xcert, _ := tls.LoadX509KeyPair("cert2.crt", "key2.pem")
select {
case <-time.After(3 * time.Minute):
c.Certificates = []tls.Certificate{xcert}
c.BuildNameToCertificate()
fmt.Println("cert switched!")
}
}(tlsConf)
Run Code Online (Sandbox Code Playgroud)
但是,这不起作用,因为服务器没有"读入"更改的配置.无论如何要求服务器重新加载TLSConfig?
我正在使用Zend Autoloader加载Zend类,以便将Zend_AMF与我的应用程序集成.在我安装APC 3.1.9并启用它之前,一切都运行良好.
我收到此错误:
Fatal error: Access to undeclared static property: Zend_Loader_Autoloader::$_instance in C:\blahblah
Run Code Online (Sandbox Code Playgroud)
我假设APC似乎在使用自动加载器和静态属性以及静态方法时遇到问题.
APC是3.1.9版本,安装在Windows 7机器上,PHP 5.3.8在Apache 2.2服务器上作为fastCGI运行.
有没有人见过这个错误?如果是这样,有什么方法可以解决这个问题?
我有一个包含2段的div.我希望段落与div的右下角对齐.我能够使用这些参数来对齐text-align: right,但是我正在努力让这些参数与div的底部对齐.
标记很简单:
<div>
<p>content 1</p>
<p>content 2</p>
</div>
Run Code Online (Sandbox Code Playgroud)
CSS:
div{
border: 1px red solid;
height: 100px;
}
p{
text-align: right;
}
Run Code Online (Sandbox Code Playgroud)
我尝试使用position:absoluteparagrams和设置bottom: 0,但这使得段落由于绝对定位而相互重叠.
div不会跨越整个页面,因此段落文本应该在div中.
有没有办法实现这样的效果,使内容"从底部增长"?
我想要的效果是这样的(photoshopped):

以及上面的小提琴:http://jsfiddle.net/cbY6h/
我知道在弹性搜索中,我们可以在文档之间建立子/父关系.
然后,在索引时,我可以传递父ID,以便链接子文档和父文档:
$ curl -XPUT localhost:9200/blogs/blog_tag/1122?parent=1111 -d '{ "tag" : "something"}'
Run Code Online (Sandbox Code Playgroud)
无论如何,在弹性搜索中建立多对多的关系?
数据驻留在具有以下模式的MySQL数据库中:
account
========
id
name
some_property
group
========
id
name
description
account_group
=============
account_id
group_id
primary_group //This is 1 or 0 depending on whether the group is the primary group for that account.
Run Code Online (Sandbox Code Playgroud)
这是我目前的映射account(请原谅数组符号,我在PHP中使用Elastica与我的elasticsearch服务器通信):
**Mapping for account**
'name' => array(
'type' => 'string'),
'some_property' => array(
'type' => 'string'),
'groups' => array(
'properties' => array(
'id' => array('type' => 'integer'),
'primary' => …Run Code Online (Sandbox Code Playgroud) 我有一个time.Time创建使用time.Date().然后我计算出1970/1/1 00:00:00.000000000那个时间和那个时间之间的纳秒数.
然后我拿纳秒并将它们变回time.Time使用状态time.Unix().
但是,如果我将重构时间与原始使用进行比较==,则返回false.如果我减去这两次,结果持续时间为0.如果我使用这两次比较time.Equal(),则返回true.
如果我使用time.Date()与第一次相同的值创建另一个时间,则使用==比较此新时间和原始时间将得到true.
这是演示这个的代码(Golang Playground):
package main
import (
"fmt"
"time"
)
func main() {
t1 := time.Date(2016, 4, 14, 1, 30, 30, 222000000, time.UTC)
base := time.Date(1970, 1, 1, 0, 0, 0, 0, t1.Location())
nsFrom1970 :=t1.Sub(base).Nanoseconds() // Calculate the number of nanoseconds from 1970/1/1 to t1
t2 := time.Unix(0, nsFrom1970)
fmt.Println(t1)
fmt.Println(t2)
fmt.Println(t1.Sub(t2)) // 0
fmt.Println(t1 == …Run Code Online (Sandbox Code Playgroud) 我目前正在编写一些类来处理PHP Web应用程序中的本地化.
课程是:
整个应用程序正常运行,但我需要向Timezone添加更多内容.
这导致了这个问题:Locale需要Timezone的方法,这需要LocaleData的方法,这需要Locale的方法.
我怎样才能打破这种循环依赖?我应该把课程分成小块吗?有没有处理这个问题的模式?
干杯:)
我正在使用PHP的MVC应用程序,它没有使用任何框架.我正在使用RedBean来实现我的ORM,它实现了数据映射器模式,并且与doctrine类似.
根据这个问题,我理解该模型不是ORM对象.在我的项目中,我有以下场景:
需要与数据库中的许多表进行通信的"复杂"模型:
$permission->isAllowed($controller, $action, $resource)来确定是否允许用户执行所请求的操作.此外,他可能会调用$permission->getPermissions()以获取用户拥有的权限列表."简单"模型,其中模型通常可以由数据库中的1个表表示:
User模型.例如$user->changeRank(),$user->addPoints()依此类推.我现在面临的问题是查看各种框架的大多数文档,我可以看到在示例中,控制器直接与ORM进行通信.例如,这是symfony2的示例控制器:
public function createAction()
{
$product = new Product();
$product->setName('A Foo Bar');
$product->setPrice('19.99');
$product->setDescription('Lorem ipsum dolor');
$em = $this->getDoctrine()->getEntityManager();
$em->persist($product);
$em->flush();
return new Response('Created product id '.$product->getId());
}
Run Code Online (Sandbox Code Playgroud)
如果ORM不是模型,为什么允许控制器直接与它交互?它不应该与看起来像这样的模型相互作用吗?
class ProductModel{
public function newProduct($name, $price, $description){
$product = new Product();
$product->setName('A Foo Bar');
$product->setPrice('19.99');
$product->setDescription('Lorem ipsum dolor');
$em = $this->getDoctrine()->getEntityManager();
$em->persist($product);
$em->flush();
}
} …Run Code Online (Sandbox Code Playgroud) 我正在尝试编译imagemagick(imagick)扩展,以便在Windows上的非线程安全环境中使用.
我使用的是PHP 5.3.10,并将Visual C++ express设置为我的编译环境.问题是我在Apache 2.2中使用非线程安全的PHP版本作为FCGI模块.
因此,我的PHP提供了一个php5.lib而不是一个php5ts.lib.我相信这就是我收到这些错误的原因:
imagick.obj : error LNK2019: unresolved external symbol __imp__tsrm_mutex_alloc referenced in function _zm_startup_imagick
Run Code Online (Sandbox Code Playgroud)
我只在linux上构建和编译过东西,所以我不太确定如何在windows环境下执行此操作.
如何编译扩展以使其不是线程安全的?
我下载了PHP 5.3.10的threadsafe二进制文件来获取php5ts.lib的副本.然后我就可以编译扩展了.
我猜测将ZTS预处理程序指令设置为1或者0将导致扩展编译为线程安全或非线程安全.(对此不太确定,所以如果有人能告诉我这是否正确,那将非常感激.:))
然后我设置了一个运行Windows 7的虚拟机并安装了最新版本的WAMP.原因是它使用了PHP的线程安全版本.
我将dll放在PHP安装的ext文件夹中并启用它php.ini.但是,即使在WAMP中尝试了ts和nts版本之后,我也会得到:
PHP Warning: PHP Startup: Unable to load dynamic library 'c:/wamp/bin/php/php5.3.10/ext/imagick.dll' - The specified module could not be found.
in Unknown on line 0
Run Code Online (Sandbox Code Playgroud)
但问题c:/wamp/bin/php/php5.3.10/ext/imagick.dll'确实存在,是的,我已经检查了很多次.
然后我将ImageMagick降级到6.6.2-10-Q16,但仍然看到同样的问题.
在Apache 2.2上运行nts版本的PHP 5.3.10的dev机器上也会出现同样的问题(全部手动安装).
看起来我对ZTS预处理器可能是错的.如果我设置ZTS=0和编译,在编译的dll上使用依赖walker仍然表明它需要php5ts.dll哪个只存在于线程安全的PHP版本上.
我做了更多修补依赖性walker,发现我必须统计链接到msvc100d.dll.然后我ZTS在预处理器定义中删除了并且能够使用php5.lib …
php ×6
go ×2
alignment ×1
apc ×1
autoload ×1
autoloader ×1
compilation ×1
css ×1
html ×1
https ×1
many-to-many ×1
model ×1
orm ×1
positioning ×1
struct ×1
symfony ×1
time ×1
webserver ×1
windows ×1