php - 尝试使 PHP 代码在 bluemix 中运行

标签 php mysql ibm-cloud devops

我一直致力于一个项目,该项目涉及创建 PHP 服务,使其在本地与 Vertrigo 一起工作,然后将其上传到 IBM Bluemix。

该代码在本地似乎工作得很好,但是当尝试在 Bluemix 中找出代码时,它开始失败。

该项目由 3 个文件组成:index.htmlclient.phpserver.php。显然,问题出在 client.phpserver.php 之间。当我尝试从 client.php 调用 server.php 中定义的函数时,它只会跳过调用该函数的行,并继续执行其余部分。

这是 client.php 代码的一部分:

<?php
    if(isset($_POST['saludo']) && !empty($_POST['nombre']) && !empty($_POST['apellido'])) {
        require_once ('nusoap.php');

        $soapclient = new soapclient( 'server.php');
        $resultado = $soapclient->call('funcionsaludo',array( 'nombre'=>$_POST['nombre'],'apellido'=>$_POST['apellido']));

        $html = <<<html
            <html>
            <head></head>
            <title>Saludando...</title>
            <body bgcolor = "#9d1fc4" text = "black"><center><img src = "/images/3.jpg"></center><br><br>
            <center><b>$resultado<br><br><a href='index.html' style='color: #ffffff'>INICIO</a></b></center>
            </body>
            </html>
        html;

        echo $html;
    }

被跳过的部分是对文件 server.php 的调用,即:

$soapclient = new soapclient( 'server.php');
$resultado = $soapclient->call('funcionsaludo',array( 'nombre'=>$_POST['nombre'],'apellido'=>$_POST['apellido']));

最后,我展示了 server.php 文件的一部分:

<?php
    require_once('nusoap.php');

    $server = new soap_server;
    $server->register('funcionsaludo');
    $server->register('getData'); 
    $server->register('insertData');

    function funcionsaludo ($nombre,$apellido) {
        return "<html><head></head><body>Hola $nombre $apellido<br><br></body></html>";
    }

结果,函数funcionsaludo返回一个由“Hola $nombre $apellido”组成的字符串,但它似乎被跳过了,因为该字符串没有显示在屏幕上。

我还想补充一下,所有 3 个文件 index.htmlclient.phpserver.php 以及使用的库nusoap.php 已全部上传到 IBM Bluemix DevOps Services 内的默认项目文件夹,并且它们不在不同的文件夹或类似文件夹中。此外,我在日志中没有看到任何可以提供一些线索的错误消息。

非常感谢您提供有关为何跳过 server.php 文件中的该函数的任何帮助。谢谢!

最佳答案

嗯,在你的 HTML 变量中你有一些标签,但是为了 PHP 将其解释为文本,你应该用双引号/单引号它,如下所示:

    $html = '<html>
            <head></head>
            <title>Saludando...</title>
            <body bgcolor = "#9d1fc4" text = "black"><center><img src = "/images/3.jpg"></center><br><br>
            <center><b>$resultado<br><br><a href="index.html" style="color: #ffffff">INICIO</a></b></center>
            </body>
            </html>';

        echo $html;

否则它将被解释为 PHP 方法和函数,而这些方法和函数并不存在。我建议您更改此设置并重试,如果不起作用,请打开浏览器上的开发人员工具并查看是否渲染了任何内容(例如页面 HTML 结构)。

关于php - 尝试使 PHP 代码在 bluemix 中运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37753378/

相关文章:

php - 如何从随机位生成一个范围内的整数

表单中的 javascript 顺序下拉菜单,用于更改 URL 值

java - 当用户在我的 Spring Web 应用程序上更新他们的个人资料图片并更新他们的个人资料时,属于该用户的列表中的对象将被复制

php - bluemix 500错误简单查询

cloud - 60 秒后 IBM bluemix 超时

go - 使用 SoftLayer API 时掩码和过滤器不起作用

php - Laravel 5.1 使用 ajax 调用在数据库中保存一些东西

php - 括号之间的正则表达式值

php - SQL 查询不工作!

MySQL Left Join 查询挂起 4 小时