手机浏览 RSS 2.0 订阅 膘叔的简单人生 , 腾讯云RDS购买 | 超便宜的Vultr , 注册 | 登陆
浏览模式: 标准 | 列表分类:PHP

fpdf: This PDF document probably uses a compression technique

 使用fpdf读取PDF文件时,报错:This PDF document probably uses a compression technique which is not supported by the free parser shipped with FPDI. (See https://www.setasign.com/fpdi-pdf-parser for more details)

 
提示这个文件是采用了一个压缩格式,到官网上查看之后,发现他们提供了fpdi-pdf-paser2,但是这是收费的。。。啊啊啊,短时间内先忽略吧。毕竟这样的PDF不多。
 
后面再关注一下有没有类似的东西。
 
1、安装pdf-parser2 : FPDI PDF-Parser 2.x (setasign.com)
2、查看这里的测试代码和示例:https://www.setasign.com/products/fpdi-pdf-parser/details/
 
目前我是放弃了,因为,他develop version,要100欧,然而这只是我自己用来测试,没必要。
------
后记:
1、读了PDF的第一行,发现这个PDF版本是PDF1.5,尝试用chrome打开,另存为,无效。选择打印->另存为PDF,成功
2、网上也有教程,建议是使用ghostscript来处理,比如:php - FPDF error: This document (testcopy.pdf) probably uses a compression technique which is not supported by the free parser shipped with FPDI - Stack Overflow,代码比较简单:
PHP代码
  1. // USE GHOSTSCRIPT IF PDF VERSION ABOVE 1.4 AND SAVE ANY PDF TO VERSION 1.4 , SAVE NEW PDF OF 1.4 VERSION TO NEW LOCATION   
  2. <?php   
  3. exec('gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile="'.$srcfile_new.'" "'.$srcfile.'"');  
  4.  ?>  
结果,官网上没有mac的可执行文件,又不想编译,所以纯记录一下吧
 
-----
0227更新:
GPL Ghostscript 9.50 (2019-10-15)
Copyright (C) 2019 Artifex Software, Inc.  All rights reserved.
This software is supplied under the GNU AGPLv3 and comes with NO WARRANTY:
see the file COPYING for details.
GPL Ghostscript 9.50: Cannot open X display `(null)'.
**** Unable to open the initial device, quitting.
 
纠结。

解决Chrome的ERR_EMPTY_RESPONSE问题

在使用本地valet进行开发的时候,打开刚指定的域名,出现:ERR_EMPTY_RESPONSE

命令行下访问一切正常:curl http://xxx.dev 都能够正常访问,但就是网页不行。因此问题不是出在了所谓的防火墙上(网上很多搜到的资料都是说防火墙)
试着清除浏览器缓存之类的,发现没正常,因为我换了chrome/edge/safari,都是同样的问题。
这时候开始怀疑网络问题了。因为在访问前正好将 global 模式换成了 pac mode,于是关闭APP,访问恢复。
 
这个问题应该是在切换网络的时候,系统缓存下来了。但命令行里却是正常。。。
 
做了几次测试
1、打开PAC模式,断开网络,本地网站恢复,连接后继续不正常
2、关闭PAC模式,恢复,打开后不正常
3、因为valet的其他站点正常,尝试unlink再link ,并没有效果
4、valet secure后,https访问,正常。关闭后继续无法访问 【这里还很妖,safari在https下可以访问,edge/chrome不行】
5、sudo brew services restart dnsmasq ,无效。
6、。。。。。没重启,毕竟机器 已经运行60多天了(12:13  up 68 days, 20:44, 6 users, load averages: 2.22 2.96 3.27),先缓缓
 
---暂先使用valet secure进行访问吧
 
---updated 01-03 16:00
这个缓存不知道怎么处理了,换了一个link,恢复了。valet link othername。。。正常,难道blog这个域名有问题??

COPY:Supporting multiple TLDs in Laravel Valet

 因为最近在用valet,然后把MAMP PRO都干掉了(不能怪我啊,实在是MAMP PRO6的一些使用太反人类了。。。不知道作者是怎么想的),但现在想想反正也就是这样简单的使用,干脆就用valet了算了。其实也可以用laravel sail的。但因为4月份之前,M1版的mac上的docker都不正常。所以,就暂时放弃了,现在用用valet也算OK。80%的情况下都OK

创建个目录,valet link一下就完事了。因为现在都是laravel的项目,用起来也算方便,毕竟也是官方的工具。但因为我用frp,所以我设置valet tld 真实的域名(比如:xxx.com),这就造成,我访问demo.xxx.com,访问的是127.0.0.1,然后我映射在外面的server也是demo.xxx.com,其实这一切都OK了。然而问题是,有时候我要测试真实域名,比如就是 demo.xxx.com ,我就只能打开全局梯子。这样我访问demo.xxx.com才对应了 frp的域名。

听起来有点绕口令,说白了就是,因为用了真实域名,所以我默认访问都是本地,但外网访问我都是真实的。而我如果要测试真实的网址,反而还要爬个梯子。虽然影响不大,但还是想换换,于是我就想,valet 是不是可以允许绑定两个域名?这样的话,是不是就全解决了?本地测试一个域名,一个域名公开对外。

找了一些文章,发现默认是不支持,但有人通过hack的方法(说白了就是改模板,改配置改代码。。。。)支持了。原文在这里:https://medium.com/@simonhamp/supporting-multiple-tlds-in-laravel-valet-e3d2a963c613

我简单的COPY了一下,没排版,要看详细的,还是直接看原版吧:

XML/HTML代码
  1. Valet is great.  
  2. Occasionally though I need an app to respond on a different TLD to the default one. And there are even times when it makes sense to have an app respond on multiple TLDs (e.g. to prove some multi-domain functionality).  
  3. You may have some secure assets hosted by a third-party that requires domain verification (FontAwesome Pro). In development, that may mean it’s easier to be using the same domain as other devs on the team than add loads of different dev domains to the service’s whitelist.  
  4. In the current release of Valet, this kind of functionality isn’t natively available. Even in third-party packages like Valet+, this isn’t supported. But with a few quick changes it’s easily possible. Let me show you how.  
  5. Dnsmasq  
  6. First we’ll need to update the Dnsmasq config so that it will handle multiple TLDs.  
  7. Turns out this is really easy. Valet holds some config in ~/.config/valet/dnsmasq.conf.  
  8. In there we just need to add some config for each TLD we want to support. Add the following two lines for every TLD you want to support. Replace {tld} with the TLD, unsurprisingly.  

  9. address=/{tld}/127.0.0.1  
  10. listen-address=127.0.0.1  

  11. Then restart Dnsmasq:  

  12. sudo brew services restart dnsmasq  

  13. Valet  
  14. Now we just need to update the Valet code to support multiple domains.  
  15. Firstly, we’re going to add some values to our ~/.config/valet/config.json. I’ve opted for simply adding keys rather than changing any existing one. I’ve added a tlds array. This will be used later.  

  16. {  
  17.     ...  
  18.     "tlds": [  
  19.          "tld1",  
  20.          "tld2"  
  21.     ]  
  22. }  

  23. Then we just need to edit some Valet files and run some commands.  
  24. All of these edits I’m making directly in my globally-installed Valet (~/.composer/vendor/laravel/valet/).  

  25. // server.php, line 70  
  26. $siteName = basename(  
  27.     // Filter host to support wildcard dns feature  
  28.     valet_support_wildcard_dns($_SERVER['HTTP_HOST']),  
  29.     '.'.$tld  
  30. );  
  31. // change to:  
  32. foreach ($valetConfig['tlds'] as $tld) {  
  33.     if (strpos($_SERVER['HTTP_HOST'], '.'.$tld) === false) {  
  34.         continue;  
  35.     }  
  36.     $siteName = basename(  
  37.         // Filter host to support wildcard dns feature  
  38.         valet_support_wildcard_dns($_SERVER['HTTP_HOST']),  
  39.         '.'.$tld  
  40.     );  
  41. }  

  42. This just allows the server to respond to whichever one of the TLDs we want to support.  
  43. Now let’s update the CLI so we can generate and remove SSL certs for all of the TLDs (valet secure and valet unsecure commands). Firstly, secure:  

  44. // cli/valet.php, line 145, secure command  
  45. $app->command('secure [domain]', function ($domain = null) {  
  46.     $url = ($domain ?: Site::host(getcwd())).'.'.Configuration::read()['tld'];  
  47.     Site::secure($url);  
  48.     Nginx::restart();  
  49.     info('The ['.$url.'] site has been secured with a fresh TLS certificate.');  
  50. })->descriptions('Secure the given domain with a trusted TLS certificate');  
  51. // change to:  
  52. $app->command('secure [domain]', function ($domain = null) {  
  53.     $urls = [];  
  54.     foreach (Configuration::read()['tlds'] as $tld) {  
  55.         $url = ($domain ?: Site::host(getcwd())).'.'.$tld;  
  56.         Site::secure($url);  
  57.         $urls[] = $url;  
  58.     }  
  59.     Nginx::restart();  
  60.     $urls = implode(', ', $urls);  
  61.     info('The ['.$urls.'] site has been secured with a fresh TLS certificate.');  
  62. })->descriptions('Secure the given domain with a trusted TLS certificate');  

  63. And now the unsecure command:  
  64. // cli/valet.php, line 158, unsecure command  
  65. $app->command('unsecure [domain]', function ($domain = null) {  
  66.     $url = ($domain ?: Site::host(getcwd())).'.'.Configuration::read()['tld'];  
  67. Site::unsecure($url);  
  68. Nginx::restart();  
  69. info('The ['.$url.'] site  will now serve traffic over HTTP.');  
  70. })->descriptions('Stop serving the given domain over HTTPS and remove the trusted TLS certificate');  
  71. // change to:  
  72. $app->command('secure [domain]', function ($domain = null) {  
  73.     $urls = [];  
  74.     foreach (Configuration::read()['tlds'] as $tld) {  
  75.         $url = ($domain ?: Site::host(getcwd())).'.'.$tld;  
  76.         Site::secure($url);  
  77.         $urls[] = $url;  
  78.     }  
  79.     Nginx::restart();  
  80.     $urls = implode(', ', $urls);  
  81.     info('The ['.$urls.'] site will now serve traffic over HTTP.');  
  82. })->descriptions('Stop serving the given domain over HTTPS and remove the trusted TLS certificate');  

  83. Finally, run the following command:  

  84. valet restart 

  85. Enjoy

 

以上是仅复制未排版,嫌丑的看原文:https://medium.com/@simonhamp/supporting-multiple-tlds-in-laravel-valet-e3d2a963c613

如果不用梯子看不了,就将就点吧

 

Tags: valet, docker, frp

用ziggy来管理前端代码中的路由。

突然间不知道这个算是该放在哪个分类了,毕竟ziggy在github上的项目,也是src为PHP,dist是JS

ziggy是一个优秀的、配合laravel使用的、适合用于SAP项目的一个前端组件。对于laravel来说,他只是主要实现了一个@route的方法,放在blade模板里就行了。至于是全放还是部分放,那就看你怎么配置的了:https://github.com/tighten/ziggy#filtering-routes,比如debug相关的就应该去掉。如果前后端项目有分离,那更应该用@route(['group'])的方式来处理。
 
对于前端来说,那就更方便了,他提供了一个route的方法,可以直接用laravel路由的名字。比如route('home.index'),会生成相应的路由。如果你要用在axios或者其他里面,你得  使用url()方法,比如route('home.index').url()生成一个字符串。
 
ziggy的用法有很多,即使你不使用blade模板,官方也都提供了适用的方法,说多了也没啥用,看这里就行了:https://github.com/tighten/ziggy#filtering-routes
 
常用方法:
route('home.index') => 对应 Route::get()->name('home.index')
route('home.index',[1,2]) =>对应 Route::get('/aaa/{a}/bbb/{b}')->name('home.index') ,允许传入数据当成 参数传递
route('home.index' , {a:1,b:2}) ,同样对应上面的路由,也就是说他第二个参数除了可以传入数组外,也可以传入对象
如果你有用laravel 的route.binding功能,他生成链接的时候,会根据你在Model里的getRouteKey来输出URL,参考:https://github.com/tighten/ziggy#route-model-binding
 
更多的还是看官方吧。。。。
 

查看PHP-fpm僵尸进程并干掉它

 几个常用命令

1、pstree -ap|grep php ,这是以树型进行展示 ,如果有括号,基本上就是僵尸
2、ps -A -o stat,ppid,pid,cmd | grep -e '^[zZ]' ,如果有,那就是僵尸。毕竟都Z了
 
有兴趣的在遇到僵尸后可以strace -p跟进一下,没兴趣就直接:kill -HUP id 或者 kill -9 id了
 
当然,最好还是strace一下,这样方便排查问题,而不至于后面会频繁出现。遇到问题不要急着重启nginx和php-fpm,排查一下,不然下次可能还会出现
 
其他方法
1、ps -aux|grep -v "grep\|nginx\|php-fpm" | grep php

Tags: strace, pstree

Records:64112345678910»