简体   繁体   English

致命错误:使用批处理文件调用未定义的函数curl_init()

[英]Fatal error: Call to undefined function curl_init() using Batch File

I have a PHP that downloads files from backend. 我有一个PHP,可以从后端下载文件。 I am using WAMP in Windows 7 and it works perfectly when done through the browser. 我在Windows 7中使用WAMP,通过浏览器完成后,它可以完美运行。

Now I have created a batch file to execute the php and it shows: 现在,我创建了一个批处理文件来执行php,它显示:

Fatal error: Call to undefined function curl_init() 致命错误:调用未定义的函数curl_init()

Not sure why something that could work over in browser is not working in batch file. 不知道为什么在浏览器中可以解决的问题在批处理文件中不起作用。 Below is my code for the batch file: 以下是我的批处理文件代码:

@ECHO OFF
php.exe -f "C:\wamp\www\test\test.php"

Any idea what's the issue? 知道是什么问题吗?

uncomment the following on your php.ini 在您的php.ini上取消注释以下内容

;extension=php_curl.dll

and restart webserver. 并重新启动网络服务器。 This might be due to curl disabled in your php. 这可能是由于您的php中禁用curl所致。

When you use wamp, xamp or other all-in-one server, it uses an overrided php.ini located into bin/conf/ instead where original is. 当您使用wamp,xamp或其他多合一服务器时,它将使用位于bin / conf /中的替代php.ini代替原始位置。

You need copy from these or edit the ini located at php.exe folder. 您需要从其中复制或编辑位于php.exe文件夹中的ini。

If you cant access it (shared server, etc), you can create a custom php.ini file into script folder, and put needed instructions: 如果您无法访问它(共享服务器等),则可以在脚本文件夹中创建一个自定义php.ini文件,并放入所需的说明:

extension_dir = "c:/wamp/bin/php/php5.3.5/ext/" // change version if needed to yours
extension = php_curl.dll

When using through browser it is using WAMP and the PHP ini is from C:\\wamp\\bin\\php\\php5.4.3 通过浏览器使用时,它正在使用WAMP,PHP ini来自C:\\ wamp \\ bin \\ php \\ php5.4.3

But I have set my php directory to C:\\php-5.4.9 in environmental variables, thus when using windows batch it is calling php from that directory and there was no php.ini file there. 但是我已经在环境变量中将我的php目录设置为C:\\ php-5.4.9,因此在使用Windows Batch时,它是从该目录调用php的,那里没有php.ini文件。

I copied the PHP ini file from wamp to php folder and now it is working. 我将wini的PHP ini文件复制到php文件夹,现在可以使用了。

Apparently I have installed php and then wamp, thus there is a overlap which has caused confusion. 显然我已经安装了php,然后安装了wamp,因此出现了重叠,造成了混乱。

Solution for me: 我的解决方案:

1) sudo apt-get install php5-curl 1) sudo apt-get install php5-curl

2) restart server 2)重启服务器

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM