
EffakT
Members-
Posts
37 -
Joined
-
Last visited
Everything posted by EffakT
-
its all on the same server.
-
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.
-
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?
-
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
-
Awesome man! thanks so much <3
-
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
-
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.
-
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); ?>
-
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.
-
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).
-
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
-
Is this returning any errors? are you running XAMPP?
-
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.
-
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?
-
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...
-
sorry, what are 'composite index'? and how do you make them?
-
So, basically I am trying to make a forum, and I am wondering how other forum software do this? On the index page, there are all the categories, with their boards. This, I understand how to do. What I don't know how do is the "Latest Post" for each board. I have this query so far, but it doesn't work. SELECT topics.*, Users.Name AS AuthorName FROM topics INNER JOIN Users ON Users.ID = topics.Author FULL OUTER JOIN Comments ON Comments.Topic = topics.ID WHERE topics.Board = 1 ORDER BY Comments.Date, topics.Date DESC LIMIT 1 Is there a better way of doing this? My table structures: -- phpMyAdmin SQL Dump -- version 4.0.4.1 -- http://www.phpmyadmin.net -- -- Host: 127.0.0.1 -- Generation Time: Feb 23, 2014 at 04:46 AM -- Server version: 5.5.32 -- PHP Version: 5.4.19 SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; SET time_zone = "+00:00"; /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; /*!40101 SET NAMES utf8 */; -- -- Database: `forums` -- CREATE DATABASE IF NOT EXISTS `forums` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci; USE `forums`; -- -------------------------------------------------------- -- -- Table structure for table `board` -- CREATE TABLE IF NOT EXISTS `board` ( `ID` int(11) NOT NULL AUTO_INCREMENT, `Name` varchar(80) NOT NULL, `Description` text NOT NULL, `Category` int(11) NOT NULL, PRIMARY KEY (`ID`), UNIQUE KEY `ID` (`ID`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=5 ; -- -- Dumping data for table `board` -- INSERT INTO `board` (`ID`, `Name`, `Description`, `Category`) VALUES (1, 'First Board', 'Im in Category 1 :3', 1), (2, 'Board 2', 'I''m the second board :3', 2), (3, 'Baord3', 'Cat1', 1), (4, 'Board4', 'Cat2', 2); -- -------------------------------------------------------- -- -- Table structure for table `categories` -- CREATE TABLE IF NOT EXISTS `categories` ( `ID` int(11) NOT NULL AUTO_INCREMENT, `Name` varchar(80) CHARACTER SET utf8 NOT NULL, `Description` text NOT NULL, PRIMARY KEY (`ID`), UNIQUE KEY `ID` (`ID`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 AUTO_INCREMENT=3 ; -- -- Dumping data for table `categories` -- INSERT INTO `categories` (`ID`, `Name`, `Description`) VALUES (1, 'Category1', 'I am the first category'), (2, 'Category2', 'I''m the second category :3'); -- -------------------------------------------------------- -- -- Table structure for table `comments` -- CREATE TABLE IF NOT EXISTS `comments` ( `ID` int(11) NOT NULL AUTO_INCREMENT, `Content` text NOT NULL, `Date` datetime NOT NULL, `Topic` text NOT NULL, `Author` int(11) NOT NULL, PRIMARY KEY (`ID`), UNIQUE KEY `ID` (`ID`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; -- -------------------------------------------------------- -- -- Table structure for table `topics` -- CREATE TABLE IF NOT EXISTS `topics` ( `ID` int(11) NOT NULL AUTO_INCREMENT, `Subject` varchar(80) NOT NULL, `Date` datetime NOT NULL, `Board` int(11) NOT NULL, `Author` int(11) NOT NULL, `Content` text NOT NULL, PRIMARY KEY (`ID`), UNIQUE KEY `ID` (`ID`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=4 ; -- -- Dumping data for table `topics` -- INSERT INTO `topics` (`ID`, `Subject`, `Date`, `Board`, `Author`, `Content`) VALUES (1, 'Topic 1', '2014-02-04 00:00:00', 1, 1, 'CONTENT :3'), (2, 'New Subject', '2014-02-04 00:00:00', 2, 1, 'Board 2'), (3, 'New Subject', '2014-02-03 00:00:00', 2, 1, 'Board 2 Thread2'); -- -------------------------------------------------------- -- -- Table structure for table `users` -- CREATE TABLE IF NOT EXISTS `users` ( `ID` int(11) NOT NULL AUTO_INCREMENT, `Name` varchar(80) NOT NULL, `Password` varchar(80) NOT NULL, `Email` varchar(80) NOT NULL, `LastOnline` datetime NOT NULL, `RegisteredDate` datetime NOT NULL, PRIMARY KEY (`ID`), UNIQUE KEY `ID` (`ID`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ; -- -- Dumping data for table `users` -- INSERT INTO `users` (`ID`, `Name`, `Password`, `Email`, `LastOnline`, `RegisteredDate`) VALUES (1, 'awesomeusername', 'iwillbeencodedeventually', 'awesome@email.com', '2014-02-21 00:00:00', '2014-02-20 00:00:00'); /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; Thanks --EffakT
-
We don't want the user's post to be cleared of spaces, just need to clear the white-space so the regex will work.
-
the database content looks like this: It is then called from the database. Regex is run to format it into html it is then echoed like: <p><?php $content ?></p>
-
Setting up a blog, and I want to be able to insert lists, urls, bold, italics, etc, etc, using bbcode.
-
What regex should be used to clear the whitespace? e.g when getting the content from database, wouldn't It need to clear all of the whitespace for that regex to work?
-
could you by change explain what $p1 matches/does?
-
The first paragraph doesn't get closed and the last paragraph doesn't get opened. :/
-
<?php $content = "<p>Content Content Content [ol] [li]First Dimension [ol] [li]Second Dimension[/li] [/ol] [/li] [li]Back to First Dimension[/li] [/ol] More Content :3 [ol] [li]First Dimension [ol] [li]Second Dimension[/li] [/ol] [/li] [li]Back to First Dimension[/li] [/ol] More Content :3</p>"; if (strpos($content,"[ol]") !== false) { $content = str_replace("[ol]", "<ol>", $content); $content = str_replace("[/ol]", "</ol>", $content); $content = str_replace("[li]", "<li>", $content); $content = str_replace("[/li]", "</li>", $content); } if (strpos($content,"[ul]") !== false) { $content = str_replace("[ul]", "<ul>", $content); $content = str_replace("[/ul]", "</ul>", $content); $content = str_replace("[li]", "<li>", $content); $content = str_replace("[/li]", "</li>", $content); } $content = preg_replace('~(<([uo]l)>.*</\\2>)~s', "</p>$1<p>", $content); echo $content; ?>
-
<p>Content Content Content </p><ol> <li>First Dimension <ol> <li>Second Dimension</li> </ol> </li> <li>Back to First Dimension</li> </ol> More Content :3 <ol> <li>First Dimension <ol> <li>Second Dimension</li> </ol> </li> <li>Back to First Dimension</li> </ol><p> More Content :3</p> line 10.