PHP Question Error

PHP Question Error

por Utpal Das -
Número de respuestas: 9
While editing a CodeRunner question, I have selected PHP question type from the drop-down menu and put a simple question for displaying "Hello" (please refer attached). However, I am getting the following error: "qtype_coderunner/Language php is not available on this system". What's going wrong and how to fix please?
En respuesta a Utpal Das

Re: PHP Question Error

por Richard Lobb -

I don't know. It should work. I haven't used php questions myself for years, but the test suite still includes a couple of PHP test questions. No-one else has reported problems.

Normally that message means that you're using a language that isn't supported on the Jobe server, but it's hard to see how that could have come about.

I attach a simple PHP question that works fine on my machine. Try importing that and let me know what happens when you preview it and run the sample answer.

Can you confirm that other languages are working OK? If not, your Jobe server is probably broken.

Are you a sysadmin with access to the Jobe server? If so, please run the Jobe test as documented here and let me know what happens.


En respuesta a Richard Lobb

Re: PHP Question Error

por Utpal Das -

Error message repeated after importing this question and preview with the sample answer. Already using C, Java  and Python3 without any issues, and tried to run PHP for the first time.  

I had earlier set up the server, however having limited access in this lockdown period.  While the detailed test could not be done, I could run simpletest.py which showed:

Supported languages:
    c: 5.4.0
    cpp: 5.4.0
    java: 1.8.0_242
    nodejs: 4.2.6
    octave: 4.0.0
    python3: 3.5.2
No task file is present for php..

-rw-r--r-- 1 root root      1602 Feb 15  2019 c_task.php
-rw-r--r-- 1 root root      1602 Feb 15  2019 c_task.php-original
-rw-r--r-- 1 root www-data  1567 Aug 14  2018 cpp_task.php
-rw-r--r-- 1 root www-data  3729 Aug 14  2018 java_task.php
-rw-r--r-- 1 root www-data  3596 Aug 14  2018 matlab_task.php
-rw-r--r-- 1 root www-data  1466 Aug 14  2018 nodejs_task.php
-rw-r--r-- 1 root www-data  2514 Aug 14  2018 octave_task.php
-rw-r--r-- 1 root www-data  1808 Aug 14  2018 pascal_task.php
-rw-r--r-- 1 root www-data  1168 Aug 14  2018 python2_task.php
-rw-r--r-- 1 root root      1426 Sep 13  2018 python3_task.php
ls: cannot open directory '/var/www/html/jobe/files': Permission denied
PHP Version => 7.0.33-0ubuntu0.16.04.14
En respuesta a Utpal Das

Re: PHP Question Error

por Richard Lobb -

Well that's odd - a file seems to have gone missing from your Jobe server. Could you or a sysadmin have deleted it?

I suggest you just reload it from github: https://github.com/trampgeek/jobe/blob/master/application/libraries/php_task.php

You might also want to check directory permissions on /var/www/html/jobe/application/libraries - it should 770, owned by www-data. Jobe tasks should not be able to see into the application directory tree, let alone delete files from it.

En respuesta a Richard Lobb

Re: PHP Question Error

por Utpal Das -
Thanks, Richard, After placing php_task.php under libraries, php task could be executed. However, there seem to be an issue in collecting the results.

For a simple "Hello" program, it did display "Hello" but something extra came: 

define('SEPARATOR', '##');


;

(Please refer Screenshot #1 and 2)

And following error occurred after running the sqr function question you had supplied: "Expected 3 test results, got 1. Perhaps excessive output or error in question?"
(Please refer Screenshot #3)

Marcas:
En respuesta a Utpal Das

Re: PHP Question Error

por Utpal Das -

Update: Looks like my template somehow got changed as:

{{ STUDENT_ANSWER }}

define('SEPARATOR', '#<ab@17943918#@>#');

{% for TEST in TESTCASES %}

{{ TEST.testcode }};

{% if not loop.last %}

echo SEPARATOR;

{% endif %}

{% endfor %}

When I removed all lines except the first one in this template, Hello program worked correctly. However, the sqr function is still having the same error messages. The original template may help..

Marcas:
En respuesta a Utpal Das

Re: PHP Question Error

por Richard Lobb -

The original template was correct. I suspect that the problem was that your submitted answer for the Hello.php example finished with a line

?>

which turned off PHP interpretation. That would result in 

define('SEPARATOR', '#<ab@17943918#@>#');
echo SEPARATOR;

appearing in the output after the student's output. The first line would be rendered by the browser without the contents in angle brackets. 

With that particular template, the student answer must start with <?php but must not close the PHP scope. It's over to you as a question author to decide what you want. If you want students to always close the scope, you can re-open it in the template. Or you can do the opening and closing within the template.

Note that you can see what's going on by turning on template debugging in your question.

En respuesta a Richard Lobb

Re: PHP Question Error

por Utpal Das -

Thanks, Richard. That too worked for Hello. However, sqr test question you had supplied is still facing an error: “Expected 3 test results, got 1. Perhaps excessive output or error in question?”

Marcas:
En respuesta a Utpal Das

Re: PHP Question Error

por Richard Lobb -

It looks like you're running an older version of CodeRunner. There was a bug in the PHP question type that was fixed in October 2018, and you seem to have a version from before then.

To fix it, change the following line in the php question prototype:

define('SEPARATOR', '#<ab@17943918#@>#');

to

define('SEPARATOR', "#<ab@17943918#@>#\n");

Or, better, upgrade your version of CodeRunner!