简体   繁体   English

从Shell运行PHP脚本时cURL无法正常运行

[英]cURL not functioning correctly when PHP script run from Shell

I have a cron.php file which fetches data from a webpage and saves it daily. 我有一个cron.php文件,该文件从网页获取数据并每天保存。 This webpage requires authentication to access the data being retrieved, and therefore the cron.php file uses cURL to login and save the cookie, then using this cookie when requesting the final page. 此网页需要进行身份验证才能访问要检索的数据,因此cron.php文件使用cURL登录并保存cookie,然后在请求最终页面时使用此cookie。

The cron.php file is stored on a windows server and therefore I need to use the windows task scheduler to execute it daily. cron.php文件存储在Windows服务器上,因此我需要使用Windows任务计划程序每天执行一次。 I have the windows scheduled task setup to call shellscript.vbs 我有Windows计划的任务设置来调用shellscript.vbs

shellscript.vbs shellscript.vbs

Set WinScriptHost = CreateObject("WScript.Shell")
WinScriptHost.Run Chr(34) & "C:\Apache24\htdocs\Salesforce\script.bat" & Chr(34), 0
Set WinScriptHost = Nothing

script.bat 脚本

"C:\PHP\php.exe" -f "C:\Apache24\htdocs\Salesforce\cron.php"

The issue is that for some reason cURL is not able to access the target page when cron.php is run through this process. 问题是由于某种原因,当cron.php在此过程中运行时,cURL无法访问目标页面。 When I execute cron.php in my web browser it downloads the page and updates the local file just fine, it is only through executing the script.bat contents that it fails. 当我在Web浏览器中执行cron.php时,它会下载页面并更新本地文件,这只是通过执行script.bat内容而失败。

I'm thinking there is an issue with cURL not being able to use the cookie properly or not following the redirect, and this is the reason it is not retrieving the correct data but I have absolutely no idea. 我认为cURL不能正确使用cookie或未按照重定向进行操作是有问题的,这就是为什么它无法检索正确的数据,但是我绝对不知道。

我最终只是为Windows安装了wget并使用了以下命令:

"C:\Program Files (x86)\GnuWin32\bin\wget.exe" -q -O NUL http://example.com/cron.php

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

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