php提示Fatal error: Call to undefined function imagecreate()
例,我在测试一个简单生成图形时实例
Example #1 新建一个新的 GD 图像流并输出图像
代码如下 | 复制代码 |
<?php |
运行机制时提示
Fatal error: Call to undefined function imagecreate() .....
后面突然想起没打开gd库了
这一问题是:GD库没有正确安装或配置,解决方案:
在php.ini中找到
;extension=php_gd2.dll
去掉前边的;
然后将php目录中的ext下的php_gd2.dll拷入c:/windows/system32和c:/windows目录下,重启IIS或者apache就OK了.
centos中gd库开启
具体操作只有2个命令如下:
运行在线安装带GD库的PHP的命令:
代码如下 | 复制代码 |
yum -y install php-gd |
重新启动apachce服务以使安装后的GD库生效
代码如下 | 复制代码 |
/etc/rc.d/init.d/httpd restart(service httpd restart) |
gd的安装路径
/etc/php.d/gd.ini <---这个是让php支持gd的哦,这个是CentOS的特色之一,不用把全部东西都写在php.ini这个文件里,只是需要把*.ini文件写在/etc/php.d/文件夹就可以了,系统会自动把这个目录下的*.ini读入php.ini
/usr/lib/php/modules/gd.so <----这个就是gd的文件啦
关于需要使用GD库的图形处理函数还有如下
gd_info
getimagesize
getimagesizefromstring
image_type_to_extension
image_type_to_mime_type
image2wbmp
imageaffine
imageaffinematrixconcat
imageaffinematrixget
imagealphablending
imageantialias
imagearc
imagechar
imagecharup
imagecolorallocate
imagecolorallocatealpha
imagecolorat
imagecolorclosest
imagecolorclosestalpha
imagecolorclosesthwb
imagecolordeallocate
imagecolorexact
imagecolorexactalpha
imagecolormatch
imagecolorresolve
imagecolorresolvealpha
imagecolorset
imagecolorsforindex
imagecolorstotal
imagecolortransparent
imageconvolution
imagecopy
imagecopymerge
imagecopymergegray
imagecopyresampled
imagecopyresized
» imagecreate
imagecreatefromgd2
imagecreatefromgd2part
imagecreatefromgd
imagecreatefromgif
imagecreatefromjpeg
imagecreatefrompng
imagecreatefromstring
imagecreatefromwbmp
imagecreatefromwebp
imagecreatefromxbm
imagecreatefromxpm
imagecreatetruecolor
imagecrop
imagecropauto
imagedashedline
imagedestroy
imageellipse
imagefill
imagefilledarc
imagefilledellipse
imagefilledpolygon
imagefilledrectangle
imagefilltoborder
imagefilter
imageflip
imagefontheight
imagefontwidth
imageftbbox
imagefttext
imagegammacorrect
imagegd2
imagegd
imagegif
imagegrabscreen
imagegrabwindow
imageinterlace
imageistruecolor
imagejpeg
imagelayereffect
imageline
imageloadfont
imagepalettecopy
imagepalettetotruecolor
imagepng
imagepolygon
imagepsbbox
imagepsencodefont
imagepsextendfont
imagepsfreefont
imagepsloadfont
imagepsslantfont
imagepstext
imagerectangle
imagerotate
imagesavealpha
imagescale
imagesetbrush
imagesetinterpolation
imagesetpixel
imagesetstyle
imagesetthickness
imagesettile
imagestring
imagestringup
imagesx
imagesy
imagetruecolortopalette
imagettfbbox
imagettftext
imagetypes
imagewbmp
imagewebp
imagexbm
iptcembed
iptcparse
jpeg2wbmp
png2wbmp
你使用empty检查一个函数返回的结果时会报如下的一个致命错误:
Fatal error: Can't use function return value in write context in : ..................
例如:
echo empty(yourfunction(xx, oo));
到PHP手册里面查看,在empty函数描述的地方有以下文字:
Note: empty() only checks variables as anything else will result in a parse error. In other words, the following will not work:empty(trim($name)).
empty() 只检测变量,检测任何非变量的东西都将导致解析错误!
因此,我们不能拿empty来直接检测函数返回的值,需要先把函数的返回值赋给某个变量,然后去用empty检测这个变量。
所以,我们可以写成如下的形式:
$return= yourfunction(xx, oo);
echo empty(return);
Curl函数在php中一个默认未开启的组件,如果你需要使用Curl我们需要在php.ini中把extension=php_curl.dll前面的;去掉即可。我先是把php.ini中的extension=php_curl.dll前面的;去掉了,并且重启了apache环境,但调用如下函数时提示
代码如下 | 复制代码 |
<?php |
错误提示
Call to undefined function curl_init()
看了相关文章我又把将PHP的ext目录下的三个文件:php_curl.dll、libeay32.dll和ssleay32.dll复制到系统system32目录中,但还是不行,于是再接google发现win7(x64)有一点区别了自带的php_curl.dll文件在64位windows7环境下并不能运作
具体解决步骤:
1、单击通知栏wamp图标,在php-ext里找到php_curl选项,单击选中,等待wamp重启服务完成。
2、下载修复过的php_curl.dll(php5.X/X64位系统)文件,放置到wampbinphpphp(版本号)ext文件夹下。
3、重新启动wamp服务即可。
提示
找了这么久原来是我们安装的php环境与系统版本不同,我们最好是多少位系统选择多少位的php版本哦。
memory_limit是php.ini中的一个比较重要的参数了,它可以限制你php进行最大使用内存的情况,如果小了会导致运行时提示Fatal Error: Allowed memory size of xxxxxx bytes exhausted错误了,下面我们一起来看看解决办法。
编辑php.ini 在php.ini中,找到“memory_limit”这一项,如果没有,你可以在文件的尾部自己增加这个参数。以下是一些设置范例
memory_limit = 128M ; 可以将128M改为任何你想设置的值
保存文件
重启php web 服务器 web服务器使用Apache, 则执行:
httpd restart
你可能不被允许私修改php.ini。那么,你可以需要考虑用其他方法来增加memory_limit的值。
修改memory_limit大小方法2: .htAccess
说明: 这种方法只有在php以Apache模块来执行时才生效。 在你的网站的根目录下找到“.htaccess”文件,如果没有,可以自己创建一个。然后把以下配置放入其中
php_value memory_limit 128M ; 可以将128M改为任何你想设置的值
修改memory_limit大小方法3: 运行时修改php的内存设置
在你的php代码中增加以下命令行即可。
ini_set(‘memory_limit’,’128M’);
在运行dedecms是有些朋友会发现有些页面会提示Fatal error: Allowed memory size of 134217728 bytes exhauste错误了,下面我们一起来看看解决此问题办法。报错提示:Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 38218371 bytes) in .....
解决方法:
1.取消PHP的内存限制。
在php程序中添加 ini_set("memory_limit","-1");
2.根据自己的需要及参考本机的内存大小修改php内存限制,如改为1024M。
在php程序中添加 ini_set("memory_limit","1024M"); 或者将php.ini中相应位置改为memory_limit = 1024M;
内存限制的意义
php中的相关文档解释 memory_limit 如下:
memory_limit: integer
该指令设定了一个脚本 所能够申请到的最大内存字节数。这有助于防止写得不好的脚本消耗光服务器上的可用内存。要使用此指令必须在编译的时候激活。因此 configure 一行中应该包括:--enable-memory-limit。如果不需要任何内存上的限制,必须将其设为 -1。 从 php 4.3.2 起,当激活了 memory_limit,PHP 函数 memory_get_usage() 便可以使用了。也就是说,php在一个 page 中的处理内存限制,默认的(/etc/php.ini)定义为 128M (我的系统默认安装后),后来开发组的应用写的越来越复杂,但是在结构上可能还有些欠缺,频繁的对象请求,居然造成了内存不足。
应用层面测试与解决方法
最好的方式应该在应用层面解决,而不是不断的增加内存设置。以下为代码测试:
代码如下 | 复制代码 |
<? |
运行结果显示如下:
total runtime: 1.47 s
memory usage: 77.09 M
一个页面居然会有77M的请求。究其原因,是程序员在编码时,仅仅对变量赋值,却从来没有 unset ($var) 过。试想,如果一个页面请求要处理20个sql查询,每个sql查询返回10个sql结果,而程序员从来都不关心是返回一个row的所有column还是仅仅返回需要的column(实际上当我们采用更common的中间层时,往往会返回全部的column而不是特定的某几个字段,就像在 ORM 中如NHibernate, JBOSS中的那样)如果一条row有10K, 那么这个页面到处理结束时就要增加到 10K*10*20=2M的数组分配,这还不算有时候我们需要最数组进行复制。
所以在php中,合理的方法是变量使用后就 unset($var),最大限度节省内存资源。
经验之谈
本人有一台服务器使用的是apaceh2.3与php5.2.6上面的方法无效,经官方确认是php版本bug了,我们可以换个高版本手php版本即可解决。
相关文章
解决springboot使用logback日志出现LOG_PATH_IS_UNDEFINED文件夹的问题
这篇文章主要介绍了解决springboot使用logback日志出现LOG_PATH_IS_UNDEFINED文件夹的问题,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2021-04-28解决jquery插件:TypeError:$.browser is undefined报错的方法
首先先说一说$.browser browser就是用来获取浏览器基本信息的。 jQuery 从 1.9 版开始,移除了 $.browser 和 $.browser.version , 取而代之的是 $.support 。 在更新的 2.0 版本中,将不再支持 IE 6/7/8。 以后,如果用户需...2015-11-24Pytorch 的损失函数Loss function使用详解
今天小编就为大家分享一篇Pytorch 的损失函数Loss function使用详解,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2020-05-02PHP “Notice: Undefined variable” 和 “Notice: Undefined index”报错
下面我们来看一篇关于PHP “Notice: Undefined variable” 和 “Notice: Undefined index”报错,希望这篇文章能够帮助到各位朋友,有兴趣的朋友可以进来看看吧。...2016-11-25PHP Notice: undefined index原因与解决办法
在php开发时可能会碰到如PHP Notice: undefined index这种错误提示,下面我来给大家介绍关于undefined index错误提示的解决办法。 如 $_GET['aa']; 就会出现PHP No...2016-11-25php提示 Warning: touch() [function.touch]: Utime failed: Permission denied in错误
在使用php程序时提示Warning: touch() [function.touch]: Utime failed: Permission denied in错误,下面一起来看看此问题的解决办法。 使用timthumb.php出现Warni...2016-11-25Warning: mssql_connect() [function.mssql-connect]:
我是这样做的,确定mssql是正常的用户名密码也可以,但下面就是不行。 <?php教程 $con=mssql_connect( "localhost", "sa ", "123456 ") or die ('error'); ?>...2016-11-25Jquery attr("checked") 返回checked或undefined 获取选中失效
假设我们现在需要这样的场景:页面上有一个checkbox,我们期望通过Jquery来获得它是否选中,或者通过Jquery来让它被选中。 在JQ1.6之前的版本,我们会这样写我们的代码: 复制代码 代码如下: <input type='checkbox' id='cb'/>...2013-10-13Java8通过Function获取字段名的方法(获取实体类的字段名称)
Java8通过Function获取字段名。不用再硬编码,效果类似于mybatis-plus的LambdaQueryWrapper,对Java8通过Function获取字段名相关知识感兴趣的朋友一起看看吧...2021-09-29php CURLOPT错误Warning: curl_setopt() [function.curl-setopt]:...
在我们使用php curl函数时提示Warning: curl_setopt() [function.curl-setopt]: CURLOPT_FOLLOWLOCATION cannot be activated when in safe_mode or an open_basedir...2016-11-25- 这篇文章主要介绍了精读《Vue3.0 Function API》,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2020-05-20
php Fatal error: Call to undefined function imagecreatefromjpeg()
imagecreatefromjpeg函数是一个图像处理函数,但在使用中发现Fatal error: Call to undefined function imagecreatefromjpeg()错误了,下文小编整理了一些教程,大家一起来...2016-11-25php连接mysql提示Call to undefined function mysql_connect()
今天在windows中配置了php mysql环境,很高兴测试一段代码结果提示Call to undefined function mysql_connect()这证明数据库配置不成功哈。 代码如下 ...2016-11-25php提示Notice: Use of undefined constant错误
下面整理了在使用php时出现的Use of undefined constant错误的解决办法,因这关于提示Use of undefined constant错误是配置问题并不是程序错误,下面给大家整理一下解决...2016-11-25Warning: mssql_query() [function.mssql-query]:
Warning: mssql_query() [function.mssql-query]: message: 不能用 DB-Library(如 ISQL)或 ODBC 3.7 或更早版本将 ntext 数据或仅使用 Unicode 排序规则的 Unicode 数据...2016-11-25Call to undefined method DebugBar\\DebugBar::info()
我们看到英文Call to undefined method就知道是因为函数或方法没有定义了,这个对于插件就有可能是什么功能没有开启了,我们下面来看看Call to undefined method DebugBa...2016-11-25- 这篇文章主要介绍了Java8特性使用Function代替分支语句,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下...2020-09-09
iconv() [function.iconv]: Detected an illegal character in
本文章来给大家介绍iconv() [function.iconv]: Detected an illegal character in 错误的几种解决办法,有需要了解的朋友可参考。 用iconv函数将gb2312转换为utf-8...2016-11-25PHP Warning: implode() [function.implode]: Invalid
今天在做一个小的采集发布接口时发现使用implode函数老提示出错,但在网上找了一下解决不了,后来仔细看一原因是写法错误了,当然因这个问题也学了不少东西下面给各位整理...2016-11-25ASP.NET MVC @Helper辅助方法和@functons自定义函数的使用方法
本文主要介绍ASP.NET MVC中使用@Helper和@functons自定义一些代码片段,方便视图调用,从而达到减少重复代码,快速开发的目的,希望对大家有所帮助。...2021-09-22