重造 PHP -HTTP 性能检测,新增 List<int>、HashMap<K, V>

1 天前
 2024

https://github.com/php-any/origami

在访问 hello work 场景下,和 go http 标准库接近,2 万左右 qps 。

同时新增了更加便捷的查询


$db = open("mysql", "root:root@/temp");

$db->ping();

Database\registerDefaultConnection($db);

@Table("users")
class User {
    public int $id;
    
    @Column("name")
    public string $userName;
    
    public int $age;
    
    public float $coin;
    
    @Column("create_at")
    public string $createAt;
}

$data = DB<User>();

echo "=== 基础查询 ===\n";
$user = $data->where("id = ?", 100)->first();
dump($user);

除了 array 数组外,还有增强数组

$list = new List<int>();
$list->add(1);
$list->add(2);
$list->add(3);

// 手动迭代
$list->rewind();
while ($list->valid()) {
    echo "索引: " . $list->key() . ", 值: " . $list->current() . "\n";
    $list->next();
}

KV 方式的泛型类

$map = new HashMap<string, int>();
$map->put("apple", 10);
$map->put("banana", 20);
$map->put("orange", 30);
322 次点击
所在节点    PHP
0 条回复

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/1168205

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX