PHP 上的系统调用
对此有点问题。 脚本 A 调用/包含脚本 B。脚本 B 必须执行系统调用并返回到脚本 A。失败了。 当我单独调用脚本 B 时,它工作得很好,我一生都无法通过在 A 上调用它来使其工作。我已经尝试过
- 将其包含在 A 中,
- 并在 A 中使用另一个系统调用来调用它,
- 制作一个 bash 脚本调用 B 然后用 A 调用该 bash 脚本(起始)
我在这里有什么选择?
编辑代码:
<?php
//B.php
//works fine when called on its own
function readsite ($url)
{
$output=system("curl -ks $url");
return $output;
}
?>
<?php
//A.php
include_once("B.php");
$url="www.google.com";
$read=readsite($url);
echo $read;
?>
Having a bit of problem with this.
Script A calls/includes Script B. Script B has to execute a system call and return to Script A. Fails in flames.
When I call Script B on its own, it works just fine, I cannot for the life of me get it to work by calling it on A. Ive already tried
- Including it on A
- Calling it with another system call within A
- Making a bash script that calls B and then calling that bash script with A (I N C E P T I O N)
What are my options here?
Edit for code:
<?php
//B.php
//works fine when called on its own
function readsite ($url)
{
$output=system("curl -ks $url");
return $output;
}
?>
<?php
//A.php
include_once("B.php");
$url="www.google.com";
$read=readsite($url);
echo $read;
?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我假设您在这里试图解决的问题是获取网站的内容。
尝试以下操作:
curl 扩展为您提供了一种相对理智且稳定的方式来获取 php 中的内容。 查看文档以获取更多信息
这假设 php-curl 可用不过扩展。
当然(正如 lonesomeday 指出的那样)您应该将方案添加到 url(使用“http://www.google.com”作为 url)。
I assume that the problem you are trying to solve here is fetching the contents of a website.
Give the following a try:
The curl extension provides you with a relatively sane and stable way to fetch stuff in php. Look at the docs for more information
This assumes availability of the php-curl extension though.
And of course (as lonesomeday pointed out) you should add the scheme to the url (use 'http://www.google.com' as url).