php – 苏demo的别样人生 https://www.libaocai.com 行走于凡尘俗世,活得别样人生 Mon, 27 Nov 2023 01:46:06 +0000 zh-CN hourly 1 https://wordpress.org/?v=6.2.4 PHP 8.3 发布,一起来看看新增了哪些特性 https://www.libaocai.com/7269.html Mon, 27 Nov 2023 01:46:06 +0000 https://www.libaocai.com/?p=7269 PHP 语言发布了 8.3 版本。主要新特性包括:

类型化类常量,动态获取类常量,

新增 #[\Override] 属性,只读属性深拷贝,

新增 json_validate() 函数,

新增 Randomizer::getBytesFromString() 方法,

新增 Randomizer::getFloat() 和 Randomizer::nextFloat() 方法,命令行 linter 支持多个文件,

新的类、接口和函数,此外还有性能改进、bug 修复等等。

  • 新增 DOMElement::getAttributeNames()、DOMElement::insertAdjacentElement()、DOMElement::insertAdjacentText()、DOMElement::toggleAttribute()、DOMNode::contains()、DOMNode::getRootNode()、DOMNode::isEqualNode()、DOMNameSpaceNode::contains() 和 DOMParentNode::replaceChildren() 方法。
  • 新增 IntlCalendar::setDate()、IntlCalendar::setDateTime()、IntlGregorianCalendar::createFromDate() 和 IntlGregorianCalendar::createFromDateTime() 方法。
  • 新增 ldap_connect_wallet() 和 ldap_exop_sync() 函数。
  • 新增 mb_str_pad() 函数。
  • 新增 posix_sysconf()、posix_pathconf()、posix_fpathconf() 和 posix_eaccess() 函数。
  • 新增 ReflectionMethod::createFromMethodName() 方法
  • 新增 socket_atmark() 函数。
  • 新增 str_increment()、str_decrement() 和 stream_context_set_options() 函数。
  • 新增 ZipArchive::getArchiveFlag() 方法。
  • 支持在 OpenSSL 扩展中使用自定义 EC 参数生成 EC 密钥。
  • 新增 INI 设置 zend.max_allowed_stack_size 用于设置允许的最大堆栈大小。
  • php.ini 现在支持后备/默认值语法。
  • 匿名类现在可以是只读的。

详情可查看:https://www.php.net/releases/8.3/zh.php

转载请注明:苏demo的别样人生 » PHP 8.3 发布,一起来看看新增了哪些特性

]]>
php 计算区间时间内工作日的函数 https://www.libaocai.com/7266.html Wed, 22 Nov 2023 02:56:08 +0000 https://www.libaocai.com/?p=7266 一个比较有意思的函数,可以实现计算任意时间区间内工作日的函数。

这样你就能很方便的计算你每年的工作日有多少了。

/**
 * @param $start_date  开始日期
 * @param $end_date  结束日期
 * @param $weekend_days 一周休息天数
 *
 * @return array
 */
function getWeekendDays($start_date, $end_date, $weekend_days=1) {

    $data = array();

    $start_reduce = $end_add = 0;

    $start_N = date('N',strtotime($start_date));

    $end_N = date('N',strtotime($end_date));

    // 进行单、双休判断,默认按单休计算
    $weekend_days = intval($weekend_days);
    switch ($weekend_days)
    {

        case 2:

            in_array($end_N,array(6,7)) && $end_add = ($end_N == 7) ? 2 : 1;

            $start_reduce = ($start_N == 7) ? 1 : 0;

            break;

        case 1:

        default:

            $end_add = ($end_N == 7) ? 1 : 0;

            break;

    }

    $days = ((strtotime($end_date) - strtotime($start_date))/86400) + 1;

    $data['total_days'] = $days;

    $data['total_relax'] = floor(($days + $start_N - 1 - $end_N) / 7) * $weekend_days - $start_reduce + $end_add;

    return $data;

}

echo "Two days per week\n";

var_dump( getWeekendDays("2022-01-01","2022-12-31",1));

转载请注明:苏demo的别样人生 » php 计算区间时间内工作日的函数

]]>
mac简单操作安装php mongodb扩展 https://www.libaocai.com/7212.html Wed, 23 Nov 2022 04:34:28 +0000 https://www.libaocai.com/?p=7212 首先检测php mongdb扩展服务

php -m |grep “mongodb”

如果返回结果为空,那么代表没有安装mongodb扩展服务。

进入php bin目录

cd /usr/local/opt/php\@7.3/bin/

执行:

./pecl install mongodb

安装成功会有上面的提示。

检测 : php -m |grep “mongodb”

重启php 服务

brew services restart php@7.3

如此,完成。

转载请注明:苏demo的别样人生 » mac简单操作安装php mongodb扩展

]]>
mac下简单操作安装php yaf扩展支持 https://www.libaocai.com/7205.html Wed, 23 Nov 2022 02:54:09 +0000 https://www.libaocai.com/?p=7205 最近有个刚接手的项目采用了yaf开发,由于博主的电脑没有yaf扩展,所以简单安装记录了下操作步骤,以供有需要的网友们参考。

本机环境: mac OS Monterery 12.3.1 , php7.3

参考php官方文档:https://www.php.net/manual/zh/yaf.installation.php

首先检测本机pecl支持性,输入: pecl -v

输入安装命令: pecl install yaf

显示结果:

然后重启php 服务: brew services restart php@7.3

检测扩展安装: php -m|grep “yaf”

写个phpinfo 看看。

至此,安装php yaf扩展完成。

此外使用windows的小伙伴们可以参考以下网址的内容,注意监察自己的php Thread Safety状态。

https://pecl.php.net/package/yaf

转载请注明:苏demo的别样人生 » mac下简单操作安装php yaf扩展支持

]]>
mac下安装php-redis扩展支持 https://www.libaocai.com/7202.html Wed, 06 Jul 2022 03:43:43 +0000 https://www.libaocai.com/?p=7202 命令:

wget http://pecl.php.net/get/redis-4.3.0.tgz
tar -xzvf redis-4.*.tgz
cd redis-4.*/
phpize
./configure --with-php-config=/usr/local/opt/php\@7.*/bin/php-config
make
make install
make test

sudo vim vim /usr/local/etc/php/7.3/php.ini
添加内容:
extension="redis.so"

brew services restart php@7.3 

转载请注明:苏demo的别样人生 » mac下安装php-redis扩展支持

]]>
mac升级后php@7.3 has been disabled解决办法 https://www.libaocai.com/7199.html Wed, 06 Jul 2022 03:38:12 +0000 https://www.libaocai.com/?p=7199 检测brew服务状态

brew docktor

匹配brew里已有的php

brew search php

卸载

brew uninstall php@7.3
rm -rf /usr/local/etc/php/7.3

重新安装

brew install php@7.3

提示Error: php@7.3 has been disabled because it is a versioned formula!

解决办法:

brew tap shivammathur/php

brew install shivammathur/php/php@7.3

如果系统里有好多个php,可以清理下,示例:

brew uninstall –ignore-dependencies php@8.1

brew link php@7.3

转载请注明:苏demo的别样人生 » mac升级后php@7.3 has been disabled解决办法

]]>
laravel的command定时任务配置说明 https://www.libaocai.com/7178.html Fri, 13 Aug 2021 08:17:01 +0000 http://www.libaocai.com/?p=7178 配置示例:

->cron('* * * * *');	#在自定义Cron调度上运行任务
->everyMinute();	#每分钟运行一次任务
->everyFiveMinutes();	#每五分钟运行一次任务
->everyTenMinutes();	#每十分钟运行一次任务
->everyFifteenMinutes();	#每十五分钟运行一次任务
->everyThirtyMinutes();	#每三十分钟运行一次任务
->hourly();	#每小时运行一次任务
->hourlyAt(17);	#每小时第十七分钟运行一次任务
->daily();	#每天凌晨零点运行任务
->dailyAt('13:00');	#每天13:00运行任务
->twiceDaily(1, 13);#每天1:00 & 13:00运行任务
->weekly();	#每周运行一次任务
->monthly();	#每月运行一次任务
->monthlyOn(4, '15:00');	#每月4号15:00运行一次任务
->quarterly();	#每个季度运行一次
->yearly();	#每年运行一次
->timezone('Asia/Shanghai');	#设置时区

$schedule->call(function () {
    // 每周星期一13:00运行一次...
})->weekly()->mondays()->at('13:00');

// 工作日的上午8点到下午5点每小时运行...
$schedule->command('foo')
         ->weekdays()
         ->hourly()
         ->timezone('Asia/Shanghai')
         ->between('8:00', '17:00');

转载请注明:苏demo的别样人生 » laravel的command定时任务配置说明

]]>
php关于redis geo命令的常用示例 https://www.libaocai.com/7172.html Fri, 21 May 2021 06:44:01 +0000 http://www.libaocai.com/?p=7172 Redis GEO 主要用于存储地理位置信息,并对存储的信息进行操作,该功能在 Redis 3.2 版本新增。

Redis GEO 操作方法有:

  • geoadd:添加地理位置的坐标。
  • geopos:获取地理位置的坐标。
  • geodist:计算两个位置之间的距离。
  • georadius:根据用户给定的经纬度坐标来获取指定范围内的地理位置集合。
  • georadiusbymember:根据储存在位置集合里面的某个地点获取指定范围内的地理位置集合。
  • geohash:返回一个或多个位置对象的 geohash 值。

geoadd 示例:

$redis->geoadd("city", 117.224311, 39.111515, "天津")

geopos 示例:

$redis->geopos("city", "天津") 

geodist 示例:

$redis->geodist("city","天津", "北京","km")

georadius 示例:

$redis->georadius("city", 117.224311, 39.111515, 1000, "km", ['WITHDIST','ASC'])

georadiusbymember 示例:

$redis->georadiusbymember("city", "天津", 200, "km", ['WITHCOORD', 'WITHDIST', 'ASC'])
  //Array ( [0] => Array ( [0] => 天津 [1] => 0.0000 [2] => Array ( [0] => 117.22431153059005737 [1] => 39.11151424175071867 ) ) [1] => Array ( [0] => 北京 [1] => 113.8093 [2] => Array ( [0] => 116.40378087759017944 [1] => 39.91543907825245441 ) ) )

geohash 示例

$redis->geohash("city", "天津", "北京")

转载请注明:苏demo的别样人生 » php关于redis geo命令的常用示例

]]>
mac brew 安装php amqp扩展支持 https://www.libaocai.com/7150.html Fri, 27 Nov 2020 08:54:06 +0000 http://www.libaocai.com/?p=7150 1.安装rabbitmq-c 支持

brew install rabbitmq-c
#查看安装目录
cd /usr/local/Cellar/rabbitmq-c/

2.pecl安装扩展

pecl install amqp

提示:Set the path to librabbitmq install prefix [autodetect]

# 输入rabbitmq-c安装目录位置 (0.10.0)是安装的版本目录
/usr/local/Cellar/rabbitmq-c/0.10.0

3.安装完后重启php

brew services restart php@7.3

转载请注明:苏demo的别样人生 » mac brew 安装php amqp扩展支持

]]>
delaying job queue on lumen 7 在lumen7中使用延迟队列 https://www.libaocai.com/7144.html Thu, 19 Nov 2020 04:18:18 +0000 http://www.libaocai.com/?p=7144 公司有个项目采用的lumen后台框架,由于业务需要使用延迟队列。 技术小伙伴们反馈只用过:
dispatch(new Jobs());

不知道怎么实现延迟队列,搜了xueyuanjun和中文文档说明的写法:

ProcessPodcast::dispatch($podcast)
              ->delay(now()->addMinutes(10));
提示:
Call to undefined method App\Jobs\GetCityInfoDelay::dispatch()
发现在stackoverflow上也有一些国外的道友有提问:
I have a project on Lumen 7 which includes a lot of queues but I can't get to delay the job.

This is how I dispatch a job:
dispatch(new NotifyJob($user, $template));

but when I add this:
 dispatch(new NotifyJob($user, $template))->delay(now()->addMinutes(10));

I get this error

"Call to undefined method Laravel\\Lumen\\Bus\\PendingDispatch::delay()"

    And doing this EmailJob::dispatch($user, $template); gives me Undefined method dispatch
I just can\'t get the delay to work.
但是, no one answers.
通常什么情况下的提问会是没有人愿意回答呢?
第一种:世上的人都不会,显然这种情况不太可能。
第二种,太简单,懒得理。
记住一句话:当你在使用别人东西的时候,如果发现不会用,一定要好好翻翻原版手册。
记住第二句话:不要经常吃别人嚼过的东西,然后还感觉很香,导致丧失了自己撕咬品尝的能力。
于是找到了lumen的官方文档,关于队列的使用说明 有这么一段:
 you may use the dispatch function to dispatch jobs from anywhere within your Lumen application:
    dispatch(new ExampleJob);
Of course, you may also use the Queue facade.
If you choose to use the facade, be sure to uncomment the call to $app->withFacades() in your bootstrap/app.php file:
Queue::push(new ExampleJob);
Queue 是lumen里的一种门面模式,里面支持Queue的多种方法,例如延迟执行可以使用以下:
Queue::later(Carbon::now()->addMinutes(10),new GetCityInfoDelay());
在lumen里使用队列服务和laravel里是存在区别的,lumen7 不提供jobs生成器,如果需要可以复制ExampleJob 文件,然后改造。
自定义Job继承Job ,job 使用了 InteractsWithQueue, Queueable, SerializesModels traits.

转载请注明:苏demo的别样人生 » delaying job queue on lumen 7 在lumen7中使用延迟队列

]]>