| Reference | Downloads | Github

Pavlovia: my jspsych experiment requires an external php file

URL of experiment:

Description of the problem:

I’ve coded my experiment in jspsych but provide external .json condition files for each participant. The problem here is that I need a way to reference a new file for every new participant. I figured a way to do this is to have a function that counts the number of files in the data folder and assigns file number based on that.

I.e.: (pseudocode)
subj_number = length(files in data)
condition_file = subject_file + subj_number + .json

From what I’ve gathered there’s no way of doing this directly using js code.
I’ve found a way to do this calling a .php script. And it works on my computer (on a local XAMPP server), however after I upload the whole experiment to Pavlovia if throws out an error reading the .php file :
Uncaught SyntaxError: Unexpected token <
I assume the issue is that Pavlovia doesn’t have a .php backend (but correct me if I’m wrong, I’m not very familiar with the topic).

So my question is, what is the easiest way around this issue? Can I somehow install php manually? Or can I write a python script that counts up the files and link it to the index.js file somehow? Or maybe there is another simpler solution?


P.S/ I’m not putting a link to URL, since currently uploaded version is working (since doesn’t include the .php call; I was making sure everything works fine)

We definitely can’t support you having a PHP script running on our server (security disaster). What PsychoPy/PsychoJS does is add a timestamp to data files so that they ensure no overwrites. Maybe you could do something similar? Adding a datestamp doesn’t require any PHP or interaction with the underlying filesystem (which is where the security issue comes in).

@apitiot might have an alternative solution for you

Hi Jon,

Thanks for the reply. From the way I see it, a timestamp would not solve the issue, because there is no way to bind the timestamp to a condition file unless I knew the timestamp in advance.

I.e. if I have a file named ‘participant3.json’, and a timestamp of when he started the experiment, there is still no way for the code to bind that file to that participant.

Oh, sorry, I mis-read. I thought you wanted to enforce unique data files but you want unique conditions files. Then I don’t have an easy solution for you. I guess you could interrogate the gitlab repository for the ( and count the files there using JS. Or you assign the participant number/condition as part of the URL in advance (so participant “3” is decided at recruit time rather than at start time)

This is basically what I was trying to do. The issue being that from what I found is there is no direct way of listing files using pure js. I could do it using either php code, node.js or through a python call somehow. Do you know if any of these methods is viable?

That’s a good idea, but I fear it might run into a similar issue: to know which participant is next (and which number to assign in the url), the code needs some kind of indication of how many participants already started the experiment

1 Like

Hi @SpTB, I am also looking to count the number of files in the data folder with javascript. Were you able to interrogate the gitlab repository?

Hi @jon, do you have any recommendations on how to interrogate the gitlab repository?

I’ve written an app to give a consecutive participant IDs to get around this issue.

@wakecarter thanks so much! Is there any way of testing this without paying for a credit? It seems that you can not use pilot mode to test this since pilot mode requires a pilot token.

You might need to allocate some credits to the study to allow it to run - but you don’t have to spend any so long as you switch off saving incomplete data (and even then it should be fine so long as you don’t press escape twice).