Online Judge

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

DeimonDB
Forum Newbie
Posts: 9
Joined: Mon Dec 28, 2009 10:39 pm

Online Judge

Post by DeimonDB »

Hi, I'm a newbie in php, but I have experience in other programming language such as C++.

I'm trying to make an online judge system, such as http://uva.onlinejudge.org/.
Taken From wikipedia :
An online judge is an online system to test programs in programming contests. They are also used to practice for such contests. Many of these systems organise their own contests.

The system can compile and execute your code, and test your code with pre-constructed data. Submitted code may be run with restrictions, including time limit, memory limit, security restriction and so on. The output of the code will be captured by the system, and compared with the standard output. The system will then return the result. When mistakes were found in a standard output, rejudgement using the same method must be made.
Is this can be done via PHP? Can someone help me code this?
User avatar
JNettles
Forum Contributor
Posts: 228
Joined: Mon Oct 05, 2009 4:09 pm

Re: Online Judge

Post by JNettles »

Are you trying to do this to PHP web apps or compiled apps? Its certainly possible, at least on the web end but I think you'd end up using a whole array of technologies to complete something like this, especially if you end up needing to compile source code.
DeimonDB
Forum Newbie
Posts: 9
Joined: Mon Dec 28, 2009 10:39 pm

Re: Online Judge

Post by DeimonDB »

Are you trying to do this to PHP web apps or compiled apps?
I want it to be web apps.
Its certainly possible, at least on the web end but I think you'd end up using a whole array of technologies to complete something like this, especially if you end up needing to compile source code.
I'll Try to learn it -- as long as there are people guiding me :D

But Is it possible without using system function such as exec()?
Because I think we need to use exec to tell the compiler to compile the source code, and many web hosting did not give access to such functions.
User avatar
JNettles
Forum Contributor
Posts: 228
Joined: Mon Oct 05, 2009 4:09 pm

Re: Online Judge

Post by JNettles »

What kind of web apps are you wanting to do that you would need to compile? If you're just going to be running tests on PHP web apps then you wouldn't need to do any compiling.
DeimonDB
Forum Newbie
Posts: 9
Joined: Mon Dec 28, 2009 10:39 pm

Re: Online Judge

Post by DeimonDB »

Uhm I'm Sorry, but I don't quite understand what you are saying.
Here is what the online judge would do:
Receive user source code
compile the souce code
check it with multiple input datas
notify the user one of the following:
- Accepted : if the program run within time limit, and memory limit, and outputs the correctt answer on all test data.
- Wrong answer: if the program outputs wrong answer
- Time Limit Exceeded : if the program exceeds the time limit
- Memory Limit Exceeded : if the programs exceeds the memory usage limit
User avatar
omniuni
Forum Regular
Posts: 738
Joined: Tue Jul 15, 2008 10:50 pm
Location: Carolina, USA

Re: Online Judge

Post by omniuni »

You can do it without using exec(), but you'll need the system to handle the execution and reporting. The easiest way to do this would be to have users upload their files, and they would go into a queue. A process running on the server would watch for new files in the queue, run the tests, produce the results, and write them into a database, and flag the project as having been tested. At that point, the results would be available to PHP via the database, and it could display the results to the user.
DeimonDB
Forum Newbie
Posts: 9
Joined: Mon Dec 28, 2009 10:39 pm

Re: Online Judge

Post by DeimonDB »

so, how do I make this 'watcher' process?
User avatar
omniuni
Forum Regular
Posts: 738
Joined: Tue Jul 15, 2008 10:50 pm
Location: Carolina, USA

Re: Online Judge

Post by omniuni »

That's up to you. You can use chron jobs, or daemons, or find a way to have it triggered via PHP.
DeimonDB
Forum Newbie
Posts: 9
Joined: Mon Dec 28, 2009 10:39 pm

Re: Online Judge

Post by DeimonDB »

Hmm, OK. Say I have cron job with interval every 10 minutes, executing a php script.
This php script would use the exec() function too, isn't it?
User avatar
omniuni
Forum Regular
Posts: 738
Joined: Tue Jul 15, 2008 10:50 pm
Location: Carolina, USA

Re: Online Judge

Post by omniuni »

Well, most likely, you would not use PHP, unless you're testing PHP. You'd need the chron to run a Java program for Java, C for C/C++ etc. You'll need to figure out the bindings for all those languages, and you should probably have your chron jobs check every 30 seconds or so, not every 10 minutes, or users will become very impatient! As a student who has had to use WebCAT (horrid!) just waiting 3 minutes due to the system being backed up was bad enough!
DeimonDB
Forum Newbie
Posts: 9
Joined: Mon Dec 28, 2009 10:39 pm

Re: Online Judge

Post by DeimonDB »

can you give me example?
User avatar
JNettles
Forum Contributor
Posts: 228
Joined: Mon Oct 05, 2009 4:09 pm

Re: Online Judge

Post by JNettles »

I don't mean to sound harsh or anything but this project seems pretty advanced for someone of your skill level. You're talking about implementing a fairly advanced system before you even look at the PHP side of things. Unless you have a pretty thorough grounding in compilers, build tools, chrons/daemons and command scripts you may want to put this on the back-burner until later. And would this need to be multi-language? I imagine that you'd have to use a Java, .NET, and C++ compiler, create both ANT and NANT build tools.......
User avatar
omniuni
Forum Regular
Posts: 738
Joined: Tue Jul 15, 2008 10:50 pm
Location: Carolina, USA

Re: Online Judge

Post by omniuni »

I'm afraid JNettles is probably right.
DeimonDB
Forum Newbie
Posts: 9
Joined: Mon Dec 28, 2009 10:39 pm

Re: Online Judge

Post by DeimonDB »

well, how about installing this,
http://mooshak.dcc.fc.up.pt/
does this require advanced skill too?
can you help me install this?
User avatar
omniuni
Forum Regular
Posts: 738
Joined: Tue Jul 15, 2008 10:50 pm
Location: Carolina, USA

Re: Online Judge

Post by omniuni »

Just curious, but do you have your hosting set up yet? If so, what kind of plan?
Post Reply