Jump to content

EffakT

Members
  • Posts

    37
  • Joined

  • Last visited

About EffakT

  • Birthday 09/05/1995

Profile Information

  • Gender
    Male
  • Location
    Hamilton, New Zealand
  • Age
    18

EffakT's Achievements

Newbie

Newbie (1/5)

2

Reputation

  1. I check some things before executing. They can not use port 80, 8080 or 0. They MUST write to the response (httpServer), They MUST end the response. The script is only open for a second or so (however long it takes to run a CURL on it), therefore no port is open for an extended amount of time, and the process is closed right after the CURL finishes. Also, the script is deleted off the server as soon as I have my result, so there is nothing that could clog my hard drive.
  2. What it is is like a online school of sorts where I give a challenge where they must write a script in Node where the page must output certain content to a page, or read a certain file and output the file content onto a page, then I run a CURL to see if the user's script outputs what I am expecting. If it is, I let them proceed to the next lesson, otherwise I don't let them proceed. The validation and result checking is in JavaScript. All PHP does is run the Node script. Does that help explain?
  3. So, I posted a while ago about a problem with this same project, and I managed to fix it myself so marked it was solved. But, I came across another error, being if multiple users are using the website and 2 people send a request at the same time or within a very small time, One of them will fail (normally only the first one works). What happens is that the user will send some Node script to the PHP page, the PHP will then execute the script via popen, then run a CURL to get the resulting generated page, close the handle. This doesn't close the node.exe process, so I run a exec of 'taskkill /F /IM node.exe' to close the process. This is where the problem lies. Since I am closing ALL of the node.exe processes, if multiple people send a query within say 1-2 seconds (time it takes to execute and retrieve the result of the script) the first close will close the new processes, resulting in the other processes failing. My execution code is: $h = popen("start node ".$file, "r"); // Create a curl handle $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $_SERVER['HTTP_HOST'].':'.$port); curl_setopt($curl, CURLOPT_HEADER, false); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); $output = curl_exec($curl); $errno = curl_errno($curl); $err = curl_error($curl); curl_close($curl); pclose($h); exec('taskkill /F /IM node.exe'); Does anybody have any suggestions for fixing this problem? Thanks --EffakT
  4. Awesome man! thanks so much <3
  5. So, I am attempting to create a search function, and I have SELECT * FROM topics WHERE Subject LIKE '%New%' OR content LIKE '%New%' AND Author = (SELECT * FROM users WHERE Name = 'EffakT') It should search the subject and content for New, where the author is EffakT. This query doesn't work, so I was wondering if anybody could help me out? Thanks --EffakT
  6. Sweet, thanks boompa, that wasn't but problem but actually helped a lot! I run the node script in the background (this doesn't slow down my script), then run a cURL and then close node, if cURL returns an error, I run node normally since it will return an error and wont execute. This is so I can get the error that node returns.
  7. Okay, I managed to get it closing node.exe, now I just need it to not lag as much on loading Node.JS, but it seems to be logging the error: PHP Fatal error: Maximum execution time of 30 seconds exceeded in executeScript.php on line 20 New Code: <?php $a = $_GET['a']; chdir('scripts'); $a = json_decode($a); $time = round(microtime(true) * 1000); $data = ""; $file = $time.'.js'; $handle = fopen($file, 'w') or die('Cannot open file: '.$file); foreach ($a as $b) { $data .= $b."\r\n"; } preg_match('/(listen\s*\((\d*)\))/', $data, $port); $port = $port[count($port)-1]; fwrite($handle, $data); fclose($handle); error_log("Launching Node"); shell_exec('"C:\Program Files\nodejs\node.exe" '.$file); error_log("Running cURL"); exec('C:\curl '.$_SERVER['HTTP_HOST'].':'.$port, $output); error_log("killing node"); exec('taskkill /F /IM node.exe'); foreach($output as $out) { echo $out."\r\n"; } unlink($file); ?>
  8. I have been doing research on it and came up blank, I have no clue how to do it, so I was asking for some help/support.
  9. I used to always use MySQL, then moved to MySQLi and used that for everything, until I started learning OOP, in which I used PDO. Now, I only use PDO (mainly because it is required for my course).
  10. So, I am working on my assessment for class, and I am working on a script that validates Node.js code, but it seems that it is running extremely slow on the first time the port is opened. What it should do is create a js file containing the user's input, Run the script in Node.JS, Run a cURL on the script, Echo the output of the cURL, Close Node.JS (closing the open port) Delete the user's script. My php is as follows: <?php $a = $_GET['a']; chdir('scripts'); $a = json_decode($a); $time = round(microtime(true) * 1000); $data = ""; $file = $time.'.js'; $handle = fopen($file, 'w') or die('Cannot open file: '.$file); foreach ($a as $b) { $data .= $b."\r\n"; } preg_match('/(listen\s*\((\d*)\))/', $data, $port); $port = $port[count($port)-1]; fwrite($handle, $data); fclose($handle); $h = popen('"C:\Program Files\nodejs\node.exe" '.$file, 'r'); sleep(1); exec('C:\curl '.$_SERVER['HTTP_HOST'].':'.$port, $output); foreach($output as $out) { echo $out."\r\n"; } pclose($h); unlink($file); ?> Does anybody know of any other way to do this that would reduce this lag? Also, it seems that the pclose($h); isn't stopping node properly. Thanks --EffakT
  11. Is this returning any errors? are you running XAMPP?
  12. Got it working with 2 queries, The comments one runs, then in php it checks if rowCount() is 0, if so, it runs the other query.
  13. OK, I setup a query, which to my eyes should work, but then again I'm not great with SQL. SELECT COALESCE( SELECT c.ID AS cID, c.Content AS cContent, c.Author AS cAuthor, topics.Author AS tAuthor, topics.Subject AS tSubject, topics.ID AS tID FROM comments c INNER JOIN ( SELECT Topic, MAX(Date) as Date FROM comments GROUP BY Topic ) mostRecent ON c.Topic=mostRecent.Topic AND c.Date = mostRecent.Date LEFT JOIN topics ON c.Topic=topics.ID WHERE topics.Board = 1 LIMIT 1 ), ( SELECT topics.*, Users.Name AS AuthorName FROM topics INNER JOIN Users ON Users.ID = topics.Author WHERE topics.Board = 1 ORDER BY topics.Date DESC LIMIT 1 ) Any Idea?
  14. Also, with the query you posted before, how would i go about getting the topic info and the poster's info? also if there is no comments it needs to just display the topic with the poster's info...
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.